community.vmware
community.vmware copied to clipboard
How to create a host variable from an environmental variable
SUMMARY
I'm looking for a way to assign the name of my vCenter host to a variable using community.vmware.vmware_vm_inventory
ISSUE TYPE
- Documentation Report
COMPONENT NAME
community.vmware.vmware_vm_inventory
ANSIBLE VERSION
config file = /home/username/.ansible.cfg
configured module search path = ['/home/username/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /opt/ansible/vcenter_inv_20220824/lib64/python3.6/site-packages/ansible
ansible collection location = /home/username/.ansible/collections:/usr/share/ansible/collections
executable location = /opt/ansible/vcenter_inv_20220824/bin/ansible
python version = 3.6.8 (default, Aug 13 2020, 07:46:32) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
jinja version = 3.0.3
libyaml = True
I'm using the community.vmware
collection v2.7.0. The doc for the vmware_vm_inventory module says I can use the compose
parameter to create host variables from jinja2 expressions, so I tried:
compose:
vcenter_server: lookup('env','VMWARE_SERVER')
and
compose:
vcenter_server: "{{ lookup('env','VMWARE_SERVER') }}"
I have confirmed that the environmental variable VMWARE_SERVER is set, but the variable vcenter_server
is not instantiated in the host record. Neither invocation threw an error or warning.
Is there a way to create a host variable from an environmental variable?
If not, for this specific requirement, is there a way to get the name of the vCenter server from the inventory module itself?
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.
This looks like a general question on using Ansible and not related to this collection directly.
And, anyway, issues should be created to report bugs or request new features. Not to ask questions how to do things. Try the forum for this.