diff --git a/deploy/deploy.py b/deploy/deploy.py index d0974be..a1e3a78 100755 --- a/deploy/deploy.py +++ b/deploy/deploy.py @@ -1,53 +1,53 @@ #!/usr/bin/env python3 # PYTHON_ARGCOMPLETE_OK import argparse, argcomplete import subprocess, re -ANSIBLE="/usr/local/bin/ansible-playbook" +ANSIBLE="ansible-playbook" BOOK="main.yml" HOSTS="hosts" TAGS=[] TAGS_LIST=[] # # PREPARE # list_tags = str(subprocess.check_output([ANSIBLE, '-i', HOSTS, '--list-tags', BOOK])) regex = re.compile('\[([a-z, ]+)\]', re.MULTILINE) find_tags = re.findall(regex, list_tags) clean_tags = set() for t in find_tags: clean_tags.update(t.split(', ')) TAGS_LIST = list(clean_tags) # # ARGS # parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description='''Ansible deploy script for Toy Cluser''', epilog=''' Examples: ./deploy.py ./deploy.py -t beegfs ./deploy.py -t packages ssh ''' ) parser.add_argument('-t', choices=TAGS_LIST, nargs='+') parser.set_defaults(tags=[]) argcomplete.autocomplete(parser) args = parser.parse_args() TAGS = args.tags # # MAIN # command= [ANSIBLE, '--inventory-file', HOSTS] if len(TAGS) > 0: command.extend(['--tags', ','.join(TAGS)]) command.extend([BOOK]) print (' '.join(command) + '\n') subprocess.call(command)