maschmann/php-ansible

Can't use dynamic inventories

Closed this issue · 4 comments

When trying to run a playbook on a groups of hosts on AWS that are defined on a dynamic playbook, nothing is done because ansible seems to be unable to find the hosts. If i run the playbook directly from the CLI, they are executed as expected. If i put the IP addresses directly to the inventory, the playbook runs correctly, but since the hosts are changing constantly, this is far from ideal

Is there an extra parameter i should pass to the Ansible object for it to pick up the dynamic hosts?

@ariponce are the hostnames mapped locally in your hosts file or are they available via DNS?
It's quite strange that your hosts are not resolved when wrapping ansible within php - what php version do you use and how are you calling the lib? From within a web application or just via commandline?
Maybe you can provide some more information to help me reproduce :-)

Sorry about the delay, i was on holidays.
The lib is called from the command line. The php version is 7.0.15-1 on Debian 8.1.
Here are my hosts as defined on the inventory file:

[tag_Role_webserver]

[tag_Role_testserver]

[webservers:children]
tag_Role_webserver

[testservers:children]
tag_Role_testserver

I'm using the official EC2 external inventory script

Hello @ariponce, I'm also sorry for responding that late.
I'll have to reproduce this behavior locally first, but I think the environment vars might noch be accessible when ansible is called via php. Your hosts are set within the context of your current user's process, but php is executed with the php user in another process and does not have access. I'm not sure how this could be (easily) circumvented.

After close to one year no further discussion