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="myplaybook.yml",
stats=stats,
callbacks=playbook_cb,
runner_callbacks=runner_cb,
check=True # Change to false to run it.
)
for (play_ds, play_basedir) in zip(pb.playbook, pb.play_basedirs):
import ipdb
ipdb.set_trace()
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/1bd90e0a-9e6d-4ab2-8308-95ef0ff1aaae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.