I have written below script that will end the playbook if IOS version running on router satisfies below conditions:
-
Version is greater than or is 16.12.02 AND
-
Version is NOT certain versions like 16.12.05 OR 16.09.06 OR 17.03.02’, etc as mentioned below.
But script does not work. When i run this for a device with version 16.12.05, script fails though it shouldn’t be as per the condition.
But when i test the ‘AND’ and ‘OR’ condition separately, they work. It’s just that when i combine them, it doesn’t seem to. What should i change?
tasks:
- name: GATHER DEVICE FACTS
ios_facts:
- name: END THIS PLAYBOOK IF DEVICE IS ALREADY RUNNING NEW IMAGE OR HIGHER VERSION THAN THAT
fail:
msg: DEVICE IS ALREADY RUNNING NEW IMAGE OR HIGHER VERSION THAN THAT. HENCE UPGRADE IS NOT NECESSARY
when:
-
ansible_net_version is version(‘16.12.06’, ‘>=’)
-
"ansible_net_version is version(‘16.12.05’, ‘!=’) or
ansible_net_version is version(‘16.09.06’, ‘!=’) or
ansible_net_version is version(‘17.03.02’, ‘!=’) or
ansible_net_version is version(‘17.03.03’, ‘!=’) or
ansible_net_version is version(‘17.05.01’, ‘!=’) or
ansible_net_version is version(‘17.07.01’, ‘!=’)"
I modified OR syntax and tried below syntax but didn’t work:
- name: END THIS PLAYBOOK IF DEVICE IS ALREADY RUNNING NEW IMAGE OR HIGHER VERSION THAN THAT
fail:
msg: DEVICE IS ALREADY RUNNING NEW IMAGE OR HIGHER VERSION THAN THAT. HENCE UPGRADE IS NOT NECESSARY
when:
-
ansible_net_version is version(‘16.12.04’, ‘>=’)
-
(ansible_net_version is version(‘16.12.05’, ‘!=’) or ansible_net_version is version(‘16.09.06’, ‘!=’) or ansible_net_version is version(‘17.03.02’, ‘!=’) or ansible_net_version is version(‘17.03.03’, ‘!=’))
Thanks,
Vikram