when: var is defined deprecated?

22 views
Skip to first unread message

pixel fairy

unread,
Sep 20, 2016, 6:42:50 AM9/20/16
to Ansible Project
using ansible 2.1.1.0

running a task with 'when: users is defined' works fine for hosts that have that variable. for hosts that dont, the play still runs, but gives a warning that in the future, an undefined variable will be a fatal error. is there another way of running tasks based on the existence of a given var?

Matt Martz

unread,
Sep 20, 2016, 10:11:17 AM9/20/16
to ansible...@googlegroups.com
You should generally provide your full task, so I'm going to take a guess here.

I am pretty sure the problem is that you are using `with_items: users` also.  The problem is that `when` statements are evaluated *after* `with_items`, since the `when` statement is evaluated per item in the loop. 

On Tue, Sep 20, 2016 at 5:42 AM, pixel fairy <pixel...@gmail.com> wrote:
using ansible 2.1.1.0

running a task with 'when: users is defined' works fine for hosts that have that variable. for hosts that dont, the play still runs, but gives a warning that in the future, an undefined variable will be a fatal error. is there another way of running tasks based on the existence of a given var?

--
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/c5e217aa-c58b-41c6-ad76-4911e6fdd8f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

pixel fairy

unread,
Sep 20, 2016, 1:13:45 PM9/20/16
to Ansible Project
yes. used a group so the when was not needed.

On Tuesday, September 20, 2016 at 7:11:17 AM UTC-7, Matt Martz wrote:
You should generally provide your full task, so I'm going to take a guess here.

I am pretty sure the problem is that you are using `with_items: users` also.  The problem is that `when` statements are evaluated *after* `with_items`, since the `when` statement is evaluated per item in the loop. 
On Tue, Sep 20, 2016 at 5:42 AM, pixel fairy <pixel...@gmail.com> wrote:
using ansible 2.1.1.0

running a task with 'when: users is defined' works fine for hosts that have that variable. for hosts that dont, the play still runs, but gives a warning that in the future, an undefined variable will be a fatal error. is there another way of running tasks based on the existence of a given var?

--
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.
Reply all
Reply to author
Forward
0 new messages