I'm working on a project that will use a number of devices that will need to be configured with the same plays, but separate variables. I have a vars file which includes a number of libraries, one for each device. The name of the library matches the name of the device, for example:
(Device1)
- {xxx: "AAA", yyy: "BBB", zzz: "CCC"}
- {xxx: "AAA", yyy: "BBB", zzz: "CCC"}
(Device2)
- {xxx: "AAA", yyy: "BBB", zzz: "CCC"}
- {xxx: "AAA", yyy: "BBB", zzz: "CCC"}
The play itself is supposed to figure out which library matches the device, use that library's variables and none of the other ones. My current attempt is done like this:
- name: do this
command: "do some of item.xxx with some item.zzz
- include_vars: device-library.yaml
when: "{{item}} == {{ansible_hostname}}"
But I always get:
fatal: [xxx.xxx.xxx.xxx]: FAILED! => {"failed": true, "msg": "ERROR! 'item' is undefined"}
When this project was just one device, we used with_items: stuff.yaml
all the time and it worked just fine.
My question is this: what do I have to put in place of {{item}}
, or is there a better way?