On Wednesday 02 June 2021 at 21:31:21, Vikram S wrote:

> I have written below script that will end the playbook if IOS version
> running on router satisfies below conditions:
> 
>    1. Version is greater than or is 16.12.02 AND
>    2. 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.

I think you have = and != mixed up.

> 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?

Let's work through your conditions when version = 16.12.05...

> tasks:
> 
>       - name: GATHER DEVICE FACTS
>         ios_facts:
>       - name: END THIS PLAYBOOK IF DEVICE IS ALREADY RUNNING NEW IMAGE OR
> HIGHER VERSION THAN THAT
>         fail:

So, you want it to fail when something below becomes true

>           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', '>=')

Not true - version = 16.12.05

>           - "ansible_net_version is version('16.12.05', '!=') or

Not true - version = 16.12.05, so "version != 16.12.05" is false

>             ansible_net_version is version('16.09.06', '!=') or

True - version = 16.12.05, therefore != 16.09.06

>             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', '!=')"

One of the conditions is true, therefore script fails.


I *think* you want to replace "!=" with "=" so that failure occurs only if the 
version does match one of the strings you have listed.

I might be wrong, and you want to keep "!=" but change "or" to "and" so that 
failure occurs only if version is not equal to any of the listed strings.

Either way, I think what you have written will always end up being "true".


Antony.

-- 
There are two possible outcomes:

 If the result confirms the hypothesis, then you've made a measurement.
 If the result is contrary to the hypothesis, then you've made a discovery.

 - Enrico Fermi

                                                   Please reply to the list;
                                                         please *don't* CC me.

Reply via email to