Hi all,
I need a help from you guys for writing a play if Switch Interface UP then playbook should end with error msg using when condition. I am kind of new to ansible. So please help me out for writing this task.
Thank you in advance.
What does your playbook look like?
- name: show message if interface is not down
fail:
msg: “Interface is not down”
when: {{ interface }}.operstatus == “up”
will this work?
Probably not, but you could have tried yourself?
Drop the moustaches as when conditions are already evaluated as jinja
\- name: show message if interface is not down fail: msg: "Interface is not down" when: \{\{ interface \}\}\.operstatus == "up"
will this work?
Definitely not, that is pulled from thin air if you ask me.
Try that:
when: vars.get('ansible_' + interface).active
Note:
Gather facts saves the network interface information in separate variables (e.g. ansible_eth0) instead of a dict/list,
so accessing the info for a specific item is a bit awkward.
Regards
Racke