I've been learning Ansible and am already using it for a lot of basic deployment uses, but I'm having problems with using ansible_facts for conditional statements.
Example, a statement like this is easy-
Code:
- name: Installs epel repo via yum. ONLY on CentOS machines.
yum: pkg=epel-release state=installed
when: ansible_distribution=='CentOS'
because the ansible_distribution fact is pretty straightforward
Quote:
[root@server]# ansible <machine> -m setup -a 'filter=ansible_distribution'
<machine> | SUCCESS => {
"ansible_facts": {
"ansible_distribution": "CentOS"
},
"changed": false
}
|
Other facts have much more information though, specifically I'm looking for network info-
Quote:
[root@server]# ansible <machine> -m setup -a 'filter=ansible_default_ipv4'
<machine> | SUCCESS => {
"ansible_facts": {
"ansible_default_ipv4": {
"address": "192.168.1.232",
"alias": "p128p1",
"broadcast": "192.168.1.255",
"gateway": "192.168.1.1",
"interface": "p128p1",
"macaddress": "f0:4d:a2:dc:f1:38",
"mtu": 1500,
"netmask": "255.255.255.0",
"network": "192.168.1.0",
"type": "ether"
}
},
"changed": false
}
|
The fact variable ansible_default_ipv4 has a LOT of sub information but I'm only interested in the "network" portion for my playbook.
I can't figure out the right syntax to use this though. A construction of
Code:
- name: Installs epel repo via yum. ONLY on internal network
yum: pkg=epel-release state=installed
when: ansible_default_ipv4:network=='192.168.1.0'
didn't work. What's the proper syntax to use the network property of the ansible_default_ipv4 fact?