New to Ansible, just testing it. For now, I’m using dynamic inventory scrips, and I’m trying to run simple commands on all hosts, via ansible.
I’ve setup ec2.py and digital_ocean.py in ~/ansible/, and both scripts work just fine. Provisioned with the correct credentials, if I run either script manually, I get the correct list of assets from those two cloud providers, respectively.
If I run Ansible with just one script (either ec2.py or digital_ocean.py) then that also works well:
But if I try to do just -i ~/ansible/ (hoping to use both inventory scripts in a concatenated list) then it doesn’t work. Spying the process list with pstree, I’ve noticed that ansible runs digital_ocean.py --host with all the hosts from the EC2 list. That can’t be right. No wonder it doesn’t work then.
What is the correct way to use several dynamic inventory scripts at once for something simple like -m shell -a ‘ps’?
P.S.:
If I run ./digital_ocean.py --list manually, it just throws a JSON with my hosts. But if I do ./ec2.py --list manually, then it generates first the “_meta”: tag, and then throws a list similar to the DO script. Not sure if this is relevant to the main issue, I just thought I should mention it.
Okay, I placed both inventory scripts in ~/ansible/inventory and it works. The command opens an ssh connection to each host on both clouds.
But, again, spying the process tree list while ansible is running, I’ve noticed something odd. (BTW, all runs are done after clearing the caches for both inventory scripts every time)
If I do -i ~/ansible/inventory/ec2.py, I see ansible running ec2.py --list for a while, then it initiates the ssh connections.
If I do -i ~/ansible/inventory/digital_ocean.py, I see ansible running digital_ocean.py --list for a while, then digital_ocean.py --host once for each host I have at DO, and then it launches the ssh connections.
But if I do -i ~/ansible/inventory, I see this: It runs one of the scripts with --list; it runs the other script with --list; then it runs digital-ocean.py --host for all hosts in both lists (EC2 and DO)! This is A) unnecessary, B) slow, and C) hammering the DO API servers for no good reason.
this is dependent on implementation of the inventory scripts, they can
return all host information with --list, if they do not ansible has to
call them per host also.