Skip to content

Instantly share code, notes, and snippets.

@c0psrul3
Forked from jacoelho/ansible_lambda.py
Created August 22, 2017 13:37
Show Gist options
  • Save c0psrul3/3b232fb83351168769f2c282ea15d72b to your computer and use it in GitHub Desktop.
Save c0psrul3/3b232fb83351168769f2c282ea15d72b to your computer and use it in GitHub Desktop.
ansible lambda
#!/usr/bin/python
import ansible.inventory
import ansible.playbook
import ansible.runner
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)
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