Dynamic inventory script (--host flooding)

47 views
Skip to first unread message

spezam

unread,
Apr 21, 2015, 9:14:02 AM4/21/15
to ansible...@googlegroups.com
Hello,
I'm trying to develop a script for dynamic inventory, following this (poor) documentation

I tested the script with the command
ansible --list-hosts database
which works fine and return the database hosts.

I logged the calls to the script and I can see the first call made by ansible (--list) outputs the list of hosts and their groups

{
   
"database": {
       
"hosts": [
           
"host1",
           
"host2"
       
]
   
},
   
"apache": {
       
"hosts": [
           
"host3",
           
"host4"
       
]
   
}
}


Ansible then iterates through all the hosts and call the script with --host <hostname>.

["--list"]
["--host", "host1"]
["--host", "host2"]
["--host", "host3"]
["--host", "host4"]



The performance problem obviously appears when the list of hosts and groups grows.
While I expect the '--host' call to be done only on the database hosts, it seems ansible is iterating through the full catalog.

Is that expected? Any way I can avoid this behavior?

Thanks,
Matteo

Serge van Ginderachter

unread,
Apr 21, 2015, 10:00:10 AM4/21/15
to ansible...@googlegroups.com

--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4858255e-6140-4f14-b7d7-1f8a45df1a34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

spezam

unread,
Apr 21, 2015, 10:28:54 AM4/21/15
to ansible...@googlegroups.com

Is it the only way?

I do really want to avoid to iterate through each host (instead of using arrays) and produce duplicate data...

Serge van Ginderachter

unread,
Apr 21, 2015, 10:37:19 AM4/21/15
to ansible...@googlegroups.com

On 21 April 2015 at 16:28, spezam <spe...@gmail.com> wrote:
I do really want to avoid to iterate through each host (instead of using arrays) and produce duplicate data...

​I don't understand this.​

Using the meta key allow you to return all host variables in respins to the --list call to the script, in one time.
That is an aditional key for the per host vars of course.

spezam

unread,
Apr 21, 2015, 10:47:27 AM4/21/15
to ansible...@googlegroups.com
Yeah, my only problem is that I already have the hosts array data structure available, but to produce the _meta information I have to split that information into single hosts.

I hoped I could avoid it, but I guess that's the only way.

spezam

unread,
Apr 21, 2015, 1:38:59 PM4/21/15
to ansible...@googlegroups.com
Since that was the only option, did some changes and implemented the _meta output.

Performance issue solved.

Thanks.
Reply all
Reply to author
Forward
0 new messages