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

Inventory Plugin Returns Host Variables in Unexpected Structure #712

Closed
jamesmarshall24 opened this issue Mar 13, 2021 · 6 comments · Fixed by #815
Closed

Inventory Plugin Returns Host Variables in Unexpected Structure #712

jamesmarshall24 opened this issue Mar 13, 2021 · 6 comments · Fixed by #815
Assignees
Labels
bug This issue/PR relates to a bug has_pr verified This issue has been verified/reproduced by maintainer
Milestone

Comments

@jamesmarshall24
Copy link
Contributor

jamesmarshall24 commented Mar 13, 2021

SUMMARY

Host variables returned by vmware_vm_inventory display complex variables in single line format rather than formatted correctly in a dict/list

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.vmware.vmware_vm_inventory

ANSIBLE VERSION
Ansible 2.9.18
STEPS TO REPRODUCE
  1. ansible-galaxy collection install community.vmware
  2. ansible-inventory -i vmware.yml --list
plugin: community.vmware.vmware_vm_inventory
validate_certs: False
properties:
#- 'all'
- 'name'
- 'config.name'
- 'config.guestId'
- 'config.uuid'
- 'summary.runtime.powerState'
- 'guest.hostName'
- 'guest.ipAddress'
- 'guest.ipStack'
- 'guest.guestFullName'
- 'guest.net'
- 'guest.toolsRunningStatus'
- 'guest.toolsVersion'
- 'guest.toolsStatus'
- 'guest.toolsVersionStatus'
- 'guestHeartbeatStatus'
#- 'customValue'
#- 'customValue'
keyed_groups: [
#  {key: 'config.guestId', separator: ''}
#  {key: 'summary.runtime.powerState', separator: ''},
   {key: 'tags', separator: ''}
]
EXPECTED RESULTS

Variables within config are correctly aligned in the dictionary

ansible_host: 10.10.2.20
config:
  guestId: rhel7_64Guest
  name: test-vm
  uuid: (redacted)
guest:
  guestFullName: Red Hat Enterprise Linux 7 (64-bit)
ACTUAL RESULTS
ansible_host: 10.10.2.20
config.guestId: rhel7_64Guest
config.name: test-vm
config.uuid: (redacted)
guest.guestFullName: Red Hat Enterprise Linux 7 (64-bit)

No "config" dictionary found at all in host vars. Referencing config.uuid in a playbook using this plugin results in variable not found.

@ansibullbot
Copy link

Files identified in the description:
None

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot ansibullbot added bug This issue/PR relates to a bug needs_triage Needs a first human triage before being processed. labels Mar 13, 2021
@Akasurde
Copy link
Member

@jamesmarshall24 Thanks for reporting this issue. If I understand this correctly, you want to have dictionaries inside the hostvars. For this feature, there is a configurable parameter called with_nested_properties which is False by default. You will get the following output if this parameter is set to True.

ansible-inventory -i 712_vmware.yml --list
{
    "_meta": {
        "hostvars": {
            "CentOS7_Rest": {
                "config": {
                    "guestId": "otherLinux64Guest",
                    "name": "CentOS7_Rest",
                    "uuid": "420777a5-c08b-2229-f7ea-0d90375c6c6b"
                },
...

Let me know if this satisfies your requirement.

needs_info

@Akasurde Akasurde added verified This issue has been verified/reproduced by maintainer and removed needs_triage Needs a first human triage before being processed. labels Mar 15, 2021
@Akasurde Akasurde self-assigned this Mar 15, 2021
@Akasurde Akasurde added this to the v1.9.0 milestone Mar 15, 2021
@Akasurde Akasurde added needs_info This issue requires further information. Please answer any outstanding questions question Further information is requested labels Mar 15, 2021
@jamesmarshall24
Copy link
Contributor Author

@jamesmarshall24 Thanks for reporting this issue. If I understand this correctly, you want to have dictionaries inside the hostvars. For this feature, there is a configurable parameter called with_nested_properties which is False by default. You will get the following output if this parameter is set to True.

ansible-inventory -i 712_vmware.yml --list
{
    "_meta": {
        "hostvars": {
            "CentOS7_Rest": {
                "config": {
                    "guestId": "otherLinux64Guest",
                    "name": "CentOS7_Rest",
                    "uuid": "420777a5-c08b-2229-f7ea-0d90375c6c6b"
                },
...

Thanks @Akasurde I over looked that configuration. If with that added to the yml spec, I get both. Is this expected?

ansible-inventory -i vmware.yml --list
[...]
"name": {
    "config": {
        "guestId": "rhel8_64Guest", 
        "name": "some-rhel8", 
        "uuid": "redact"
    }, 
    "config.guestId": "rhel8_64Guest", 
    "config.name": "some-rhel8", 
    "config.uuid": "redact",
[...]

The issue I'm mainly seeing are these in-line variables being written to Tower host variables. After adding that param to the yml spec, I at least don't see any undefined errors in Tower.

@ansibullbot ansibullbot removed the needs_info This issue requires further information. Please answer any outstanding questions label Mar 15, 2021
@Akasurde
Copy link
Member

@jamesmarshall24 Yes, this is expected behavior (to have in-line variables with nested variables when with_nested_properties is True).

@Akasurde
Copy link
Member

Since with_nested_properties feature was added later, we decided to set it False (default value) to maintain backward compatibility.

@Akasurde Akasurde modified the milestones: v1.9.0, v1.10.0 Apr 5, 2021
Akasurde added a commit to Akasurde/community.vmware that referenced this issue Apr 26, 2021
For AWX/Tower, setting the default value for `with_nested_properties`
as True

Fixes: ansible-collections#712

Signed-off-by: Abhijeet Kasurde <[email protected]>
@Akasurde
Copy link
Member

resolved_by_pr #815

@Akasurde Akasurde removed the question Further information is requested label Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug has_pr verified This issue has been verified/reproduced by maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants