ansible-inventory-grapher
ansible-inventory-grapher copied to clipboard
vars are not displayed correctly using yml-based inventory
We recently switched to a yml-based inventory file including all hosts, groups and vars in one file. With the ini-based everything works fine and vars are shown in the groups and hosts they are defined in. With the yml-based inventory all vars are showing in the hosts. Even when they are defined in a group.
We are using the following grapher version:
$ ansible-inventory-grapher --version ansible-inventory-grapher 2.4.5
#47 should fix this issue - will be released with 2.5.0
If you could check 2.5.0rc1, that would be helpful
Fixed by #43, released now in 2.5.0
I am still facing this issue with yaml inventories. All vars are beeing displayed in the hosts and not where the vars are defined.
Are you in the same situation as #29?
I don't really have a fix for that one other than ensuring that host vars and group vars live under the inventory.
No. The issue is, that all vars are displayed in the hosts and not in the groups where they are defined. I have created a test inventory and generated a graph with it to visualize the problem I am facing.
$ ansible-inventory-grapher -i test-inventory.yml all -a "overlap=false; splines=polyline; node [ style=filled fillcolor=lightgrey ]; rankdir=LR" | dot -Tpng -o test-inventory.png
$ ansible-inventory-grapher --version
ansible-inventory-grapher 2.5.0
all:
vars:
dnsServer:
- "192.168.0.1"
ntpServer:
- "192.168.0.1"
children:
vCenter:
vars:
vsphere_vcenter:
hostname: "vcsa.local"
username: "admin"
password: "changeme"
validateCert: False
vcsa_datacenters:
- "local"
children:
vCSA:
hosts:
vcsa.local:
ansible_host: "192.168.0.20"
vars:
vcsa_validateCert: True
vcsa_netPrefix: 24
vcsa_gateway: "192.168.0.1"
vcsa_dnsServer: "{{ dnsServer }}"
vcsa_ntpServer: "{{ ntpServer }}"
vcsa_rootPassword: "changeme"
vcsa_ssoPassword: "changeme"
vcsa_license: "xxxx-xxxx-xxxx-xxxx-xxxx"
vcsa_distributedVirtualSwitch:
- name: "vDS_{{ vcsa_datacenters[0] }}"
datacenter: '{{ vcsa_datacenters[0] }}'
version: '6.6.0'
mtu: 1500
uplinkQuantity: 2
discoveryProto: 'cdp'
discoveryOperation: 'both'
portgroups:
- name: 'Management'
vlanid: '10'
Cluster:
vars:
esxi_rootPassword: "changme"
esxi_mgmtPrimDns: "{{ dnsServer }}"
esxi_mgmtNtpIp: "{{ ntpServer }}"
esxi_validateCert: False
esxi_license: "xxxx-xxxx-xxxx-xxxx-xxxx"
children:
Cluster01:
vars:
cluster_datacenter: "{{ vcsa_datacenters[0] }}"
cluster_name: "Cluster01"
esxi_vmk:
- portgroup_name: "Management"
vds_name: "vDS_{{ vcsa_datacenters[0] }}"
enable_mgmt: true
network:
ip_address: "{{ ansible_host }}"
subnet_mask: "255.255.255.192"
default_gateway: "192.168.0.1"
hosts:
esxi01.local:
ansible_host: "192.168.0.21"
esxi02.local:
ansible_host: "192.168.0.22"
esxi03.local:
ansible_host: "192.168.0.23"
Sorry, I misunderstood this issue.
I'll see if there's anything I can do - I suspect not, I think it's a similar problem to #29 in that by the time the inventory is parsed by ansible, I can't tell what group a variable originally came from.
No problem. I should have given you a test environment right at the beginning.
If it is related to the ansible parser, then we may open an issue in the ansible project. It may be interesting to hear if it is working as designed or if it is an issue they aren't aware of.
The fix might be as simple as #44, looking at it again (doesn't fix #29, sadly)
I faced the same issue and found out that it depends on which directory you currently are.
$ ansible-inventory-grapher -i hosts.yml \all
This will list all vars in the host
$ ansible-inventory-grapher -i inventory/hosts.yml \all
This will list the vars correctly in each group.