From c15b47fb7bbcca965089afc15c2dacf2f8120758 Mon Sep 17 00:00:00 2001 From: Maykel Moya Date: Tue, 7 Jan 2014 08:36:42 +1100 Subject: [PATCH] Configure retry file usage and location Adds new settings for managing retry files: * retry_files_enabled, defaults to True * retry_files_save_path, defaults to ~/.ansible-retry This change was adapted from PR #5515. --- bin/ansible-playbook | 2 +- lib/ansible/constants.py | 3 +++ lib/ansible/playbook/__init__.py | 19 ++++++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/bin/ansible-playbook b/bin/ansible-playbook index 96e87de3eb..7793b914c4 100755 --- a/bin/ansible-playbook +++ b/bin/ansible-playbook @@ -276,7 +276,7 @@ def main(args): retries = failed_hosts + unreachable_hosts - if len(retries) > 0: + if C.RETRY_FILES_ENABLED and len(retries) > 0: filename = pb.generate_retry_inventory(retries) if filename: display(" to retry, use: --limit @%s\n" % filename) diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 861dd5325c..a255ed77d8 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -161,6 +161,9 @@ DEFAULT_CALLABLE_WHITELIST = get_config(p, DEFAULTS, 'callable_whitelist', ' COMMAND_WARNINGS = get_config(p, DEFAULTS, 'command_warnings', 'ANSIBLE_COMMAND_WARNINGS', False, boolean=True) DEFAULT_LOAD_CALLBACK_PLUGINS = get_config(p, DEFAULTS, 'bin_ansible_callbacks', 'ANSIBLE_LOAD_CALLBACK_PLUGINS', False, boolean=True) +RETRY_FILES_ENABLED = get_config(p, DEFAULTS, 'retry_files_enabled', 'ANSIBLE_RETRY_FILES_ENABLED', True, boolean=True) +RETRY_FILES_SAVE_PATH = get_config(p, DEFAULTS, 'retry_files_save_path', 'ANSIBLE_RETRY_FILES_SAVE_PATH', '~/.ansible-retry') + # CONNECTION RELATED ANSIBLE_SSH_ARGS = get_config(p, 'ssh_connection', 'ssh_args', 'ANSIBLE_SSH_ARGS', None) ANSIBLE_SSH_CONTROL_PATH = get_config(p, 'ssh_connection', 'control_path', 'ANSIBLE_SSH_CONTROL_PATH', "%(directory)s/ansible-ssh-%%h-%%p-%%r") diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 58e2bafe18..a6f67e196d 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -636,19 +636,28 @@ class PlayBook(object): buf = StringIO.StringIO() for x in replay_hosts: buf.write("%s\n" % x) - basedir = self.inventory.basedir() + basedir = C.shell_expand_path(C.RETRY_FILES_SAVE_PATH) filename = "%s.retry" % os.path.basename(self.filename) filename = filename.replace(".yml","") - filename = os.path.join(os.path.expandvars('$HOME/'), filename) + filename = os.path.join(basedir, filename) try: + if not os.path.exists(basedir): + os.makedirs(basedir) + fd = open(filename, 'w') fd.write(buf.getvalue()) fd.close() - return filename except: - pass - return None + ansible.callbacks.display( + "\nERROR: could not create retry file. Check the value of \n" + + "the configuration variable 'retry_files_save_path' or set \n" + + "'retry_files_enabled' to False to avoid this message.\n", + color='red' + ) + return None + + return filename # *****************************************************