Hello everybody,
I am writing a python script by Asible2.0 python api. My script work well
when I just run a playbook by PlaybookCLI(). Currently, I want to add a
callback with running the playbook, but the callback function is not work
in PlaybookCLI(). Who know the reason? If I mistake to use the PlaybookCLI,
how to change? Thanks for you.
My ansible version is 2.1. The below is my code and the myplaybook.yaml
just do "/usr/bin/uptime" in target machines.
#!/usr/bin/env python
from ansible.cli.playbook import PlaybookCLI
from ansible.plugins.callback import CallbackBase
class ResultCallback(CallbackBase):
def v2_runner_on_ok(self, result, **kwargs):
print("this is my test")
host = result._host
print json.dumps({host.name: result._result}, indent=4)
results_callback = ResultCallback()
my_cli=PlaybookCLI(['', '/home/vagrant/myplaybook.yaml', '-s'],
callback=results_callback)
my_cli.parse()
results=my_cli.run()
--
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/3c028ba2-e7c9-48f9-8213-4da0b376fdc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.