def run(self, resume=1):
"""Execute ansible-playbook using information gathered from config.
Args:
resume (int): Used as list index - 1 from which to resume workflow.
"""
# list index to start working on (for support of --resume)
try:
i = int(resume) - 1
except ValueError: # generally if passed a non-int
i = 0
cmds = self._config.playbook_cmds
kwargs = {
'_out': self._print_stdout,
'_err': self._print_stderr,
'_env': self._config.env
}
for counter, cmd in enumerate(cmds):
# skip execution until we reach our --resume index
# using a list slice doesn't work here since we need to be aware of
# the full list to produce a resume index on failure
if counter < i:
continue
try:
sh.ansible_playbook(*cmd, **kwargs)
except (sh.ErrorReturnCode, sh.ErrorReturnCode_1):
msg = ('An error was encountered during playbook execution. '
'Please resolve manually and then use the following '
'command to resume execution of this script:\n\n')
cmd = self._construct_resume_cli(counter + 1)
print(colorama.Fore.RED + msg + cmd)
sys.exit(1)
评论列表
文章目录