Skip to content

Host_vars and group_vars from different sources are not merged together in one inventory #9762

Closed
@abcqwertz

Description

@abcqwertz
ISSUE TYPE
  • Bug Report
SUMMARY

I am trying to merge multiple inventory sources together in one inventory. The sync of hosts and groups works fine but variables are not merged.
The host vm01.testing.local should have an additional variable „hostvar2“ which is coming from the project. The variable is not merged to the host, as you can see in the variables I get in the AWX-web-ui:

{
  "ansible_host": "vm01.testing.local",
  "ansible_uuid": "5016c76c-eec9-c883-6cc3-4366034217f2",
  "config": {
    "instanceUuid": "5016c76c-eec9-c883-6cc3-4366034217f2",
    "name": "vm01.testing.local"
  },
  "config.instanceUuid": "5016c76c-eec9-c883-6cc3-4366034217f2",
  "config.name": "vm01.testing.local",
  "configIssue": [],
  "configStatus": "green",
  "configissue": [],
  "configstatus": "green",
  "name": "vm01.testing.local",
  "runtime": {
    "connectionState": "connected"
  },
  "runtime.connectionState": "connected"
}

Here are my vCenter source variables:

---
plugin: community.vmware.vmware_vm_inventory
strict: false
validate_certs: false
with_tags: false
with_nested_properties: true
compose:
  ansible_host: config.name
  ansible_ssh_host: guest.ipAddress
  ansible_uuid: config.instanceUuid
  configissue: configIssue
  configstatus: configStatus
filters:
  - runtime.powerState == "poweredOn"
  - config.name is match('vm01\.testing\.local')
hostnames:
  - 'config.name'
groups:
  testing: config.name is match('vm01\.testing\.local')
properties:
  - 'config.name'
  - 'guest.ipAddress'
  - 'config.instanceUuid'
  - 'configIssue'
  - 'configStatus'
  - 'name'

Here is the project (git repo) layout:

  • hosts (Hostfile in INI format):
[backup_test]
tbackup.testing.local
  • host_vars/tbackup.testing.local
---
hostvar1: "This is a hostvar"
  • host_vars/vm01.testing.local
---
hostvar2: "This is a host var for a virtual machine"
  • group_vars/testing
---
groupvar: "This is a groupvar"
ENVIRONMENT
  • AWX version: 17.1.0
  • AWX install method: docker on linux
  • Ansible version: 2.9.18
  • Operating System: openSUSE LEAP 15.2
  • Web Browser: Firefox latest version
STEPS TO REPRODUCE

Create an inventory with two sources:
- First source syncs virtual machines from VMware vCenter (for source variables see summary above)
- Second source syncs hosts from a hosts file in a (Git) project (for repo setup see summary above)
- Project source also contains host_vars/group_vars for virtual machines and groups created by the first source
- Sync both sources

EXPECTED RESULTS

Host and group variables from the project source should be merged with hosts/groups created by vCenter source

ACTUAL RESULTS

Additional custom host_vars and group_vars from a project are not merged to hosts/groups created by vCenter source
It doesn’t matter if the project source has „overwrite variables“ enabled or not.

ADDITIONAL INFORMATION

I put the vCenter source variables in a file and ran the ansible-inventory command manually in the awx_task container:

ansible-inventory --list --export -i /var/lib/awx/projects/_6__awx_vmware/testing.vmware.yml  -i /var/lib/awx/projects/_19__awx_inventory/hosts --output /tmp/output.json

If i now look at output.json, I get the exptected result (As you can see the variables for the testing group and vm01.testing.local are merged successfully to the hosts and groups created by vCenter import):

{
    "_meta": {
        "hostvars": {
            "tbackup.testing.local": {
                "hostvar1": "This is a hostvar"
            }, 
            "vm01.testing.local": {
                "ansible_host": "vm01.testing.local",
                "ansible_uuid": "5016c76c-eec9-c883-6cc3-4366034217f2",
                "config": {
                    "instanceUuid": "5016c76c-eec9-c883-6cc3-4366034217f2",
                    "name": "vm01.testing.local"
                },
                "config.instanceUuid": "5016c76c-eec9-c883-6cc3-4366034217f2",
                "config.name": "vm01.testing.local",
                "configIssue": [],
                "configStatus": "green",
                "configissue": [],
                "configstatus": "green",
                "hostvar2": "This is a host var for a virtual machine",
                "name": "vm01.testing.local",
                "runtime": {
                    "connectionState": "connected"
                },
                "runtime.connectionState": "connected"
            }
        }
    },
    "all": {
        "children": [
            "backup_test",
            "testing",
            "ungrouped"
        ],
        "vars": {
            "groupvar_all": "This is a groupvar for all groups"
        }
    },
    "backup_test": {
        "hosts": [
            "tbackup.testing.local"
        ]
    },
    "testing": {
        "hosts": [
            "vm01.testing.local"
        ],
        "vars": {
            "groupvar": "This is a groupvar"
        }
    }
}

Any help is much appreciated

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions