Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vars are not displayed correctly using yml-based inventory #41

Open
digifuchsi opened this issue Aug 19, 2019 · 10 comments · May be fixed by #44
Open

vars are not displayed correctly using yml-based inventory #41

digifuchsi opened this issue Aug 19, 2019 · 10 comments · May be fixed by #44
Labels

Comments

@digifuchsi
Copy link

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

@willthames willthames added the bug label Sep 1, 2019
@willthames
Copy link
Owner

#47 should fix this issue - will be released with 2.5.0

@willthames
Copy link
Owner

If you could check 2.5.0rc1, that would be helpful

@willthames
Copy link
Owner

Fixed by #43, released now in 2.5.0

@digifuchsi
Copy link
Author

I am still facing this issue with yaml inventories. All vars are beeing displayed in the hosts and not where the vars are defined.

@willthames
Copy link
Owner

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.

@digifuchsi
Copy link
Author

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"

test-inventory

@willthames willthames reopened this Sep 17, 2019
@willthames
Copy link
Owner

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.

@digifuchsi
Copy link
Author

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.

@willthames willthames linked a pull request Sep 17, 2019 that will close this issue
@willthames
Copy link
Owner

The fix might be as simple as #44, looking at it again (doesn't fix #29, sadly)

@JPNuber
Copy link

JPNuber commented Mar 18, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants