Re: [ansible-project] Strange behaviour, possible bug

47 views
Skip to first unread message

Brian Coca

unread,
Nov 11, 2014, 11:01:21 AM11/11/14
to ansible...@googlegroups.com
cause you asked it to?

I think you want:

```
when: bar is defined
```

--
Brian Coca

cdar z

unread,
Nov 11, 2014, 11:12:15 AM11/11/14
to ansible...@googlegroups.com
Sorry, I made mistake. Bad example. I meant this one:

$ cat inv
local ansible_connection=local
$ cat extra
.yml
---
- set_fact: bar=hello
- debug: msg="baz {{ bar }}"
$ cat playbook
.yml
---
- hosts: local
  tasks
:
 
- include: extra.yml
   
when: bar is not defined
$ ansible
-playbook -i inv playbook.yml

PLAY
[local] ******************************************************************

GATHERING FACTS
***************************************************************
ok
: [local]

TASK
: [set_fact bar=hello] ****************************************************
ok
: [local]

TASK
: [debug msg="baz {{ bar }}"] *********************************************
skipping
: [local]

PLAY RECAP
********************************************************************
local                      : ok=2    changed=0    unreachable=0    failed=0  

$

Brian Coca

unread,
Nov 11, 2014, 11:44:09 AM11/11/14
to ansible...@googlegroups.com
still works as expected.

set fact runs when bar is not defined, debug is skipped on the same condition as it isn't true once set fact sets bar.

--
Brian Coca

cdar z

unread,
Nov 11, 2014, 11:53:31 AM11/11/14
to ansible...@googlegroups.com
But debug doesn't have when statement. If set_fact was runned, debug should too.

Michael Peters

unread,
Nov 11, 2014, 12:01:18 PM11/11/14
to ansible...@googlegroups.com
Adding a when condition to an include doesn't conditionally include
the file, it instead adds that condition to every task in that file.
So in this case yes, the debug does have the when statement.
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/b6ea8af7-02c5-4f3a-a100-82da2f422946%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

cdar z

unread,
Nov 11, 2014, 12:03:40 PM11/11/14
to ansible...@googlegroups.com
That's a bummer. Thank You a lot.

Dariusz C.

unread,
Nov 11, 2014, 1:01:38 PM11/11/14
to ansible...@googlegroups.com
No, still skipping. But I got the answer. Check the forum https://groups.google.com/forum/?#!topic/ansible-project/BBbdxspBzHI

2014-11-11 18:04 GMT+01:00 Petros Moisiadis <erne...@yahoo.gr>:
On 11/11/14 18:32, Petros Moisiadis wrote:
Hello,

Does it work as expected if you replace "with: bar is not defined" with "with: bar is undefined" ?

Obviously, I meant 'when: ...' and  not 'with: ...'

Reply all
Reply to author
Forward
0 new messages