Hey guys, I’m following this https://serversforhackers.com/running-ansible-programmatically but I’ve built a RESTful API around it using cherrypy.
I generate an inventory file and try to set the “host_list” variable in the ansible.playbook.PlayBook object but it doesn’t seem like this is working.
Here’s the snippet of code. The playbook I’m just passing in the string location of it, but the inventoryfile is generated according to the link above. I’m currently not removing it and I can look in /tmp and find the file and see that it’s correct.
class playbookrunner:
stats = callbacks.AggregateStats()
playbook_cb = callbacks.PlaybookCallbacks(verbose=1)
runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=1)
def init(self, inventoryfile, playbookfile):
self.inventoryfile = inventoryfile
self.playbookfile = playbookfile
def execute(self):
pb = ansible.playbook.PlayBook(
playbook=self.playbookfile,
host_list=self.inventoryfile.name,
stats=playbookrunner.stats,
callbacks=playbookrunner.playbook_cb,
runner_callbacks=playbookrunner.runner_cb,
)
return pb.run()
When I try to run this I just get “skipping: no hosts matched”
Any help here? Is it possible to generate an inventory file and actually use it?
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.