Hi Brian,
I got that via trial and error
I'm using ansible 2.4.2.0
In my case I have an inventory setup like this
inventories/uat/hosts
inventories/uat/host_vars/stable-1
inventories/uat/host_vars/stable-2
inventories/uat/group_vars/stable
in inventories/uat/hosts
[stable]
stable-1
stable-2
[stable:vars]
stable-1 http_port=80 maxRequestsPerChild=808stable-2 http_port=303 maxRequestsPerChild=909
If I run a simply play-book like this
---
- hosts: stable-1
connection: ssh
gather_facts: no
tasks:
- name: Debug http_port
debug:
var: hostvars[inventory_hostname]['http_port']
- name: Debug http_port
debug:
var: hostvars[inventory_hostname][inventory_hostname + ' http_port']
- name: Debug maxRequestsPerChild
debug:
var: hostvars[inventory_hostname]['maxRequestsPerChild']
I get
stable-1 | SUCCESS => {
"changed": false,
"hostvars[inventory_hostname]['http_port']": "VARIABLE IS NOT DEFINED!"
}
stable-1 | SUCCESS => {
"changed": false,
"hostvars[inventory_hostname][inventory_hostname + ' http_port']": "80 maxRequestsPerChild=808"
}
stable-1 | SUCCESS => {
"changed": false,
"hostvars[inventory_hostname]['maxRequestsPerChild']": "VARIABLE IS NOT DEFINED!"
}
If I define the host variables in inventories/uat/host_vars/stable-1 then it works as expected (i.e variable values available via hostvars[inventory_hostname]['http_port'] )