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,
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?