better handling of retry files

(cherry picked from commit 734bbcb1d3)
This commit is contained in:
Brian Coca 2016-06-10 14:03:05 -04:00
parent 6b286ee0c8
commit 2982b99b8e

View file

@ -28,7 +28,7 @@ from ansible.executor.task_queue_manager import TaskQueueManager
from ansible.playbook import Playbook
from ansible.template import Templar
from ansible.utils.path import makedirs_safe
from ansible.utils.unicode import to_unicode
from ansible.utils.unicode import to_unicode, to_str
try:
from __main__ import display
@ -185,8 +185,10 @@ class PlaybookExecutor:
if len(retries) > 0:
if C.RETRY_FILES_SAVE_PATH:
basedir = C.shell_expand(C.RETRY_FILES_SAVE_PATH)
else:
elif playbook_path:
basedir = os.path.dirname(playbook_path)
else:
basedir = '~/'
(retry_name, _) = os.path.splitext(os.path.basename(playbook_path))
filename = os.path.join(basedir, "%s.retry" % retry_name)
@ -258,14 +260,13 @@ class PlaybookExecutor:
re-running on ONLY the failed hosts. This may duplicate some variable
information in group_vars/host_vars but that is ok, and expected.
'''
makedirs_safe(os.path.dirname(retry_path))
try:
makedirs_safe(os.path.dirname(retry_path))
with open(retry_path, 'w') as fd:
for x in replay_hosts:
fd.write("%s\n" % x)
except Exception as e:
display.error("Could not create retry file '%s'. The error was: %s" % (retry_path, e))
display.warning("Could not create retry file '%s'.\n\t%s" % (retry_path, to_str(e)))
return False
return True