when conditionals syntax

17 views
Skip to first unread message

John Harmon

unread,
Jan 30, 2018, 11:16:37 AM1/30/18
to Ansible Project
Is something wrong with the following?  It seems to get executed no matter what.  In addition, where can I find more information about this syntax?  Is this considered jinja2 syntax? or something else?

- include_tasks: install.yml
 
when: ( install|default(false)|lower = "true" | "yes" ) && nagios_user|failed


Matt Martz

unread,
Jan 30, 2018, 11:23:29 AM1/30/18
to ansible...@googlegroups.com
Yes, you use of `| "yes"` is not proper jinja2.

`|` is used to "pipe" something into a filter function, and "yes" is not a filter function.

Are you trying to check if it also "yes".  Look to using the bool filter (also use `and` instead of `&&`):

```
when: install|default(false)|bool and nagios_user is failed
```

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/299aec3f-6321-4839-83fb-e0ba083be6a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

John Harmon

unread,
Jan 30, 2018, 11:27:37 AM1/30/18
to Ansible Project


On Tuesday, January 30, 2018 at 9:23:29 AM UTC-7, Matt Martz wrote:
Yes, you use of `| "yes"` is not proper jinja2.

`|` is used to "pipe" something into a filter function, and "yes" is not a filter function.

Are you trying to check if it also "yes".  Look to using the bool filter (also use `and` instead of `&&`):

```
when: install|default(false)|bool and nagios_user is failed
```
On Tue, Jan 30, 2018 at 10:16 AM, John Harmon <jharmon...@gmail.com> wrote:
Is something wrong with the following?  It seems to get executed no matter what.  In addition, where can I find more information about this syntax?  Is this considered jinja2 syntax? or something else?

- include_tasks: install.yml
 
when: ( install|default(false)|lower = "true" | "yes" ) && nagios_user|failed


--
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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.



--
Matt Martz
@sivel
sivel.net

Thanks Matt.  Works perfectly.  I will have to go and look up some jinja2 documentation.  Thanks again!
Reply all
Reply to author
Forward
0 new messages