Skip to content

Instantly share code, notes, and snippets.

@wolfgangmeyers
Last active July 15, 2018 01:11
Show Gist options
  • Save wolfgangmeyers/7441fa146030f6929dd0 to your computer and use it in GitHub Desktop.
Save wolfgangmeyers/7441fa146030f6929dd0 to your computer and use it in GitHub Desktop.
Run an ansible playbook from the python api
# borrowed from https://groups.google.com/forum/#!topic/ansible-project/V1PoNJcXV_w
import ansible.runner
import ansible.playbook
from ansible import callbacks
from ansible import utils
stats = callbacks.AggregateStats()
playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)
pb = ansible.playbook.PlayBook(
playbook="nseries.yml",
stats=stats,
callbacks=playbook_cb,
runner_callbacks=runner_cb,
check=True
)
for (play_ds, play_basedir) in zip(pb.playbook, pb.play_basedirs):
import ipdb
ipdb.set_trace()
# Can play around here to see what's going on.
pb.run() # This runs the playbook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment