Hi!,
I need help. I want to deploy some file with some modifications. The deployment policy is that depending on the network the server belongs to, it will deploy some files or others.
I can’t compare the “ansible_facts” with “vars”
CONFIGURATION
Example playbook:
---
- name: Create file
hosts: server
gather_facts: true
vars:
vlan:
- netname: 192.168.3.0
netface: "{{ ansible_interfaces }}"
Tasks:
tasks:
- name:
file:
path: /tmp/filetest
state: touch
when:
(hostvars[inventory_hostname]['ansible_%s' % item.0.netface]|default({}))
.get('ipv4', {}).get('network') == item.0.netname
loop:
- "{{ vlan }}"
Result:
ok: [server] => {
"ansible_default_ipv4.network": "192.168.3.0"
}
skipping: [server] => (item=[{u'netface': [u'lo', u'eth3', u'eth2', u'eth1', u'eth0'], u'netname': u'192.168.3.0'}]) => {
"ansible_loop_var": "item",
"changed": false,
"item": [
{
"netface": [
"lo",
"eth3",
"eth2",
"eth1",
"eth0"
],
"netname": "192.168.3.0"
}
],
"skip_reason": "Conditional result was False"
}
OS / ENVIRONMENT
Centos 7.7
ADDITIONAL INFORMATION
What happens is that the “when” condition is not working. And my server does have a network card on 192.168.3.0.
Thanks!,
BR