Re: [ansible-project] Need assistance in using 'AND' and 'OR' condition together

2021-06-03 Thread Brian Coca
- ansible_net_version is version('16.12.06', '>=') and
ansible_net_version not in ('17.03.02', 17.03.03', ... )



-- 
--
Brian Coca

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7dY-21pjoztouzmKx%3DOTLkQeLqdxy_L%3DOMzR3D_Fj7%3DFw%40mail.gmail.com.


Re: [ansible-project] Need assistance in using 'AND' and 'OR' condition together

2021-06-03 Thread Vikram S
Hi Antony,

On second thought, you are right in that  condition will always end up 
being "true". I guess my requirement can never be written as condition in 
ansible.

Regards,
Vikram

On Thursday, 3 June, 2021 at 1:18:08 am UTC+5:30 Antony Stone wrote:

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

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c4279f53-af16-4a7e-8139-577cb82c7545n%40googlegroups.com.


Re: [ansible-project] Need assistance in using 'AND' and 'OR' condition together

2021-06-02 Thread Vikram S
Hi Antony,

My condition to check is:

   1. 
   
   Version is greater than or is 16.12.02 (i made a typo by entering 
   16.12.06 instead fo 16.12.02 for 1st condition) AND
   2. 
   
   Version is NOT certain versions like 16.12.05 OR 16.09.06 OR 17.03.02', 
   etc as mentioned below.
   
Considering this, i am thinking my syntax was correct. Because iam using a 
AND condition, so it won't  always end up being "true.

Example:  if device is running 16.09.07, it will match both conditions and 
will fail (script will stop) which is what i want. But if version is 
16.09.06, script won't fail.
Somy issue is that this AND and OR condition don't work when used together 
but work when used separately.

Regards,
Vikram

On Thursday, 3 June, 2021 at 1:18:08 am UTC+5:30 Antony Stone wrote:

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

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5e6a0178-0734-480b-a163-1883d463c98fn%40googlegroups.com.


Re: [ansible-project] Need assistance in using 'AND' and 'OR' condition together

2021-06-02 Thread Antony Stone
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.