community.vmware icon indicating copy to clipboard operation
community.vmware copied to clipboard

How to create a host variable from an environmental variable

Open smatterchew opened this issue 2 years ago • 1 comments

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?

smatterchew avatar Aug 25 '22 18:08 smatterchew

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 avatar Aug 25 '22 18:08 ansibullbot

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.

mariolenz avatar Dec 05 '23 19:12 mariolenz