Commit f71fad70 authored by Noe Nieto's avatar Noe Nieto 💬

Add retry option for playbooks

parent 7aa5050b
......@@ -134,18 +134,21 @@ def destroy_vm(hostname):
@only_if_box_exist
def run_playbook(hostname, playbook):
def run_playbook(hostname, playbook, retry_file=None):
"""
run an Ansible playbook against this vm
"""
vagrant_wd = XDG_CONFIG_HOME.joinpath(hostname)
inventory_file = vagrant_wd.joinpath('.vagrant', 'provisioners', 'ansible', 'inventory', 'vagrant_ansible_inventory')
subprocess.run([
_args = [
'ansible-playbook', '-u', 'vagrant', '-i', f'{inventory_file}',
f'{Path(playbook).resolve()}'
],
cwd=vagrant_wd
)
]
if retry_file:
_args.extend(['--limit', f'@{Path(retry_file).resolve()}'])
subprocess.run(_args, cwd=vagrant_wd)
@only_if_box_exist
......@@ -234,8 +237,9 @@ if __name__ == '__main__':
if cmd_args.command == 'playbook':
sub_parser.usage = 'shipyard playbook hostname path/to/playbook.yml'
sub_parser.add_argument('playbook', help='The path to the playbook file')
sub_parser.add_argument('--retry', help='The path to the playbook retry file.', required=False)
sub_args = sub_parser.parse_args(sys.argv[2:])
run_playbook(sub_args.hostname, sub_args.playbook)
run_playbook(sub_args.hostname, sub_args.playbook, sub_args.retry)
sys.exit()
sub_args = sub_parser.parse_args(sys.argv[2:])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment