The inventory documentation describes setting some variables for a single
host in a hosts file
http://docs.ansible.com/ansible/latest/intro_inventory.html#host-variables
[atlanta]host1 http_port=80 maxRequestsPerChild=808host2 http_port=303
maxRequestsPerChild=909
Continuing with that example, how do you access the variable?
If I use
hostvars[inventory_hostname]['{{ inventory_hostname }} http_port']
the value I get is
80 maxRequestsPerChild=808
and I'd have to do some further splitting of the string to get the values.
Otherwise I can use a new line, but the example in Ansible docs puts them
on one line, so I was curious as to how to access them simply.
If, however I use an inventory structure such as
-- inventories
|-- group_vars
| |-- atlanta
|-- host_vars
| |-- host1
| |-- host2
|-- hosts
And in the host1 file I have
http_port: 80
maxRequestsPerChild: 808
Then I can access the variable values with
hostvars[inventory_hostname]['http_port']
hostvars[inventory_hostname]['maxRequestsPerChild']
The questions are then
1. How do I access the variables as in the first example of host variables
in the hosts file as described at
http://docs.ansible.com/ansible/latest/intro_inventory.html#host-variables ?
2. Why are the variables not consistent whether defined in a host file or
host_vars subdirectory? Is this intentional?
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/ec9b285c-7549-456e-9e34-38c1e891db86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.