我有以下变量文件:
node1_interface;
- name: eth1
ip: 10.234.10.21 mask: 255.255.255.0
我有以下剧本,我想在when条件下动态构造ansible事实变量名
vars_files:
vars/variables.ym
tasks:
- name: create interface
command: /sbin/nmcli connection create conn-name "{{ item.name }}" ifname "{{ item.name }}" ipv4 "{{ item.ip }}"
with_item: {{ vars[inventory_hostname + '_interface'] }}
when: ansible_{{ item.name }}.ipv4.address is not defined
But I am getting an error where it cannot construct the ansible fact dynamically in the when statement (It is working without the when)