Skip to content

Instantly share code, notes, and snippets.

@cetinerdev
Created August 10, 2021 19:41
Show Gist options
  • Save cetinerdev/dfe6ec2884dd2c7f312ff1ca7de344bd to your computer and use it in GitHub Desktop.
Save cetinerdev/dfe6ec2884dd2c7f312ff1ca7de344bd to your computer and use it in GitHub Desktop.
ansible vmware dynamic inventory troubleshooting
❯ cat ansible.cfg
[inventory]
enable_plugins = vmware_vm_inventory
❯ cat inventory.vmware.yaml
$ANSIBLE_VAULT;1.1;AES256
61316164336134653239363839303162666261643730376233623333376235656533323435623162
...
...
❯ ansible-inventory -i inventory.vmware.yaml --graph --vault-password-file=~/.vault_pass
@all:
|--@fedora64Guest:
| |--dhcp_4217fa4f-172a-7082-70e5-94a7097f3d43
.....
❯ cat clusterinfo.yaml
---
- name: cluster info
hosts: localhost
debugger: on_failed
connection: local
gather_facts: no
tasks:
- name: Gather cluster info from a given datacenter
vmware_cluster_info:
hostname: '{{ hostname }}'
username: '{{ username }}'
password: '{{ password }}'
validate_certs: False
datacenter: Datacenter01
❯ ansible-playbook -i inventory.vmware.yaml --vault-password-file=~/.vault_pass clusterinfo.yaml
PLAY [cluster info] **********************************************************************
TASK [Gather cluster info from a given datacenter] ***************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'hostname' is undefined\n\nThe error appears to be in '/Users/ceto/Documents/creentech-zabbix/clusterinfo.yaml': line 8, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: Gather cluster info from a given datacenter\n ^ here\n"}
[localhost] TASK: Gather cluster info from a given datacenter (debug)> p task.args
{'datacenter': 'Datacenter01',
'hostname': '{{ hostname }}',
'password': '{{ password }}',
'username': '{{ username }}',
'validate_certs': False}
[localhost] TASK: Gather cluster info from a given datacenter (debug)>
@cetinerdev
Copy link
Author

unencrypted inventory.vmware.yaml file:

plugin: vmware_vm_inventory
strict: False
hostname: x.x.x.x
username: [email protected]
password: xxxxxxx
validate_certs: False
with_tags: True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment