list of variables in YAML inventory

Hi,

I am running Ansible from a python script and I want to iterate over a dynamic list created in the python script. The inventory is also dynamically created in this script. The list is different for each host Ansible is connecting to. I don’t want to put the list into the host_vars where I want to keep only static variables. So I tried to put these variables in my dynamically created yaml inventory for each host. This does not seem to work, ansible says the list is not defined. However if I put the list in the group, it is working:

this is not working

`
ma:
hosts:
maman1-lab:
vars:
devicesids:

  • d46798753
    maman2-lab:
    vars:
    devicesids:
  • d46798752
    `

But this is working (but not what I want)

`
ma:
hosts:
maman1-lab:
maman2-lab:
vars:
devicesids:

  • d46798752
  • d46798753

`

Is it possible to associate a list of vars to a single host and not to an entire group?

thanks

Bundy

Hello Bundy,

You may use a regular text file for each host to contain the dynamically created list you wish to iterate over. This text file can then be consumed in playbook using the lookup plugin. Lookup plugins allow accessing data in Ansible from the filesystem. Below is the sample example :