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
On Saturday, February 23, 2013 3:24:25 PM UTC-8, Kyle Heath wrote:
>
> I'm new to Ansible... I would like to create a library of playbooks and
> then use ansible's python api to run the playbooks and get the result from
> a larger python script.
>
> I see there is an example <http://ansible.cc/docs/api.html> of how to use
> the ansible.runner.Runner() from python, but that seems to be useful for
> running modules. I would like to run a playbook from a yml file
> (specifying the host, and private_key parameters directly from python). I
> found the playbooks.Playbook() python class, but the constructor requires
> several parameters which I am not sure how to construct... callbacks...
> runner callbacks... etc
>
> Any pointers or any examples of how to use the python API?
>
> Cheers,
> Kyle
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/5812366a-6454-45cc-8847-98064598ec4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.