Last active
February 15, 2016 19:34
-
-
Save jacoelho/cffea1887f56e46757b1 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/python | |
| import ansible.inventory | |
| import ansible.playbook | |
| import ansible.runner | |
| import ansible.constants | |
| from ansible import utils | |
| from ansible import callbacks | |
| def run_playbook(**kwargs): | |
| stats = callbacks.AggregateStats() | |
| playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY) | |
| runner_cb = callbacks.PlaybookRunnerCallbacks( | |
| stats, verbose=utils.VERBOSITY) | |
| # use /tmp instead of $HOME | |
| ansible.constants.DEFAULT_REMOTE_TMP = '/tmp/ansible' | |
| out = ansible.playbook.PlayBook( | |
| callbacks=playbook_cb, | |
| runner_callbacks=runner_cb, | |
| stats=stats, | |
| **kwargs | |
| ).run() | |
| return out | |
| def handler(event, context): | |
| return main() | |
| def main(): | |
| out = run_playbook( | |
| playbook='test.yml', | |
| inventory=ansible.inventory.Inventory(['localhost']) | |
| ) | |
| return(out) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment