-
-
Save hari819/64016339282fd3bcd64c36a1ce850b63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import subprocess | |
| from multiprocessing import Pool | |
| import argparse | |
| def execute_playbook(pb): | |
| print("Now executing playbook: {}".format(pb)) | |
| p = subprocess.Popen("ansible-playbook -i localhost, -c local {}".format(pb), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
| while True: | |
| output = p.stdout.readline() | |
| if output == '' and p.poll() is not None: | |
| break | |
| if output: | |
| # Write to a log file, output to stdout | |
| print output.strip() | |
| rc = p.poll() | |
| stdout, stderr = p.communicate() | |
| print(stdout) | |
| print("-" * 80) | |
| return (pb, rc) | |
| def main(): | |
| parser = argparse.ArgumentParser(description='Process ansible playbooks') | |
| parser.add_argument('playbooks', metavar='PLAYBOOK', nargs='+', | |
| help='The name of an Ansible playbook.') | |
| args = parser.parse_args() | |
| playbooks = args.playbooks | |
| num_of_playbooks = len(playbooks) | |
| pool = Pool(num_of_playbooks) | |
| print("Number of playbooks to process: {}".format(num_of_playbooks)) | |
| return_codes = pool.map(execute_playbook, playbooks) | |
| print(return_codes) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment