Last active
July 15, 2018 01:11
-
-
Save wolfgangmeyers/7441fa146030f6929dd0 to your computer and use it in GitHub Desktop.
Run an ansible playbook from the python api
This file contains 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
# 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