Hi Lucio,
The filter would be evaluated first and then the not.
Consider below playbook :
---
- name: Parsing
hosts: localhost
gather_facts: no
vars:
- v1: hello
tasks:
- name: first condition
debug:
msg: First is true
when: not v1 | bool
- name: Second condition
debug:
msg: Second is true
when: not (v1 | bool)
Both the conditions in above playbook return TRUE as bool of "Hello" is
FALSE and negate of FALSE is TRUE.
Now consider another playbook:
---
- name: Parsing2
hosts: localhost
gather_facts: no
vars:
- v1: hello
tasks:
- name: first condition
debug:
msg: First is true
when: not v1
- name: Second condition
debug:
msg: Second is true
when: not v1 | bool
In this playbook the first condition would return FALSE as presence of any
string is TRUE and negate of TRUE is FALSE. Whereas in the second
condition, the string is first parsed and filtered by bool filter for
yaml-style
‘yes, on, true, false, False, Off, NO’ and other words and FALSE is
returned as no such word is found. The negate of FALSE is TRUE.
Based on above two observations, it can be concluded that bool filter is
evaluated first and then the not operator.
Therefore, to answer your second question:
Are the following expressions the same?
> when: not foo | bool
> is the same as
> when: not (foo | bool)
Yes, both the expressions are the same.
Hope this is helpful !
Thanks,
Shivharsh
On Tuesday, 9 July 2019 19:03:22 UTC+5:30, Lucio Guerchi wrote:
>
>
> I am new to Ansible and have the following questions, if I have the
> following conditional, what is going to be parsed first, the filter or the
> not, were foo is a boolean variable True or False?
>
> when: not foo | bool
>
> Are the following expressions the same?
>
> when: not foo | bool
>
> is the same as
>
> when: not (foo | bool)
>
>
On Tuesday, 9 July 2019 19:03:22 UTC+5:30, Lucio Guerchi wrote:
>
>
> I am new to Ansible and have the following questions, if I have the
> following conditional, what is going to be parsed first, the filter or the
> not, were foo is a boolean variable True or False?
>
> when: not foo | bool
>
> Are the following expressions the same?
>
> when: not foo | bool
>
> is the same as
>
> when: not (foo | bool)
>
>
On Tuesday, 9 July 2019 19:03:22 UTC+5:30, Lucio Guerchi wrote:
>
>
> I am new to Ansible and have the following questions, if I have the
> following conditional, what is going to be parsed first, the filter or the
> not, were foo is a boolean variable True or False?
>
> when: not foo | bool
>
> Are the following expressions the same?
>
> when: not foo | bool
>
> is the same as
>
> when: not (foo | bool)
>
>
On Tuesday, 9 July 2019 19:03:22 UTC+5:30, Lucio Guerchi wrote:
>
>
> I am new to Ansible and have the following questions, if I have the
> following conditional, what is going to be parsed first, the filter or the
> not, were foo is a boolean variable True or False?
>
> when: not foo | bool
>
> Are the following expressions the same?
>
> when: not foo | bool
>
> is the same as
>
> when: not (foo | bool)
>
>
On Tuesday, 9 July 2019 19:03:22 UTC+5:30, Lucio Guerchi wrote:
>
>
> I am new to Ansible and have the following questions, if I have the
> following conditional, what is going to be parsed first, the filter or the
> not, were foo is a boolean variable True or False?
>
> when: not foo | bool
>
> Are the following expressions the same?
>
> when: not foo | bool
>
> is the same as
>
> when: not (foo | bool)
>
>
On Tuesday, 9 July 2019 19:03:22 UTC+5:30, Lucio Guerchi wrote:
>
>
> I am new to Ansible and have the following questions, if I have the
> following conditional, what is going to be parsed first, the filter or the
> not, were foo is a boolean variable True or False?
>
> when: not foo | bool
>
> Are the following expressions the same?
>
> when: not foo | bool
>
> is the same as
>
> when: not (foo | bool)
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/492eb9a5-f772-4aa6-bd87-1a6e900f4c88%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.