Hi, I’m new to ansible, and i’m seeking some help. i’m writing a playbook that should iterate through a group, gather facts, then check the relevant variables against a defined condition, then perform an action depending on whether the condition is met. However, for simple conditions like x == y, i can get that to work, but when the condition is a{b{c}} == y, i cant get that to work. i think my issue here is syntax, but i’m not sure. please see a cut out of my code below, and what i’m trying to do:
This is the out put i’m trying to check the conditions against:
“ansible_net_interfaces”: {
“GigabitEthernet1”: {
“bandwidth”: 1000000,
“description”: null,
“duplex”: “Auto”,
“ipv4”: [
{
“address”: “192.168.100.14”,
“subnet”: “24”
}
],
“lineprotocol”: “up”,
“macaddress”: “0050.568b.5110”,
“mediatype”: “RJ45”,
“mtu”: 1500,
“operstatus”: “up”,
“type”: “CSR vNIC”
},
This is my code:
- hosts: cisco
vars:
HOST_COUNT: “{{ groups[‘cisco’] | length }}”
tasks:
- name: Check Status {{ item }}
gather_facts:
register: ip_brief
#- name: Check against variable - this is where i’m stuck. i want to say:
when: ansible_net_interfaces-GigabitEthernet1-ipv4-address == “192.168.100.14”
#but i dont know how to express this
- name: print
debug:
var: ip_brief
with_items:
- “{{ HOST_COUNT }}”