include task and when doesn't completely skip, variables is overwritten.

27 views
Skip to first unread message

Kai Stian Olstad

unread,
Sep 12, 2016, 7:09:10 AM9/12/16
to ansible...@googlegroups.com
Hi

I have this simple example.
It work as expected in v2.0.2 but not in 2.1.1

task1.yml
---
- name: Task 1
command: echo "1"
register: result

task2.yml
---
- name: Task 2
command: echo "2"
register: result

playbook.yml
---
- hosts: localhost
vars:
task: "1"
tasks:
- include: task1.yml
when: task == "1"

- include: task2.yml
when: task == "2"

- debug: var=result

Here task 1 should run and task 2 should be skipped, and the content in
result should be from task 1.

In Ansible 2.0.2 I get the result from task 1:

$ ansible-playbook playbook.yml

PLAY [localhost]
***************************************************************

TASK [include]
*****************************************************************
included: /home/kaistian/ansible/test/task1.yml for localhost

TASK [Task 1]
******************************************************************
changed: [localhost]

TASK [include]
*****************************************************************
skipping: [localhost]

TASK [debug]
*******************************************************************
ok: [localhost] => {
"result": {
"changed": true,
"cmd": [
"echo",
"1"
],
"delta": "0:00:00.001446",
"end": "2016-09-12 12:40:38.107604",
"rc": 0,
"start": "2016-09-12 12:40:38.106158",
"stderr": "",
"stdout": "1",
"stdout_lines": [
"1"
],
"warnings": []
}
}


In Ansible 2.1.1 result is overwritten, presumably but the skipped task
2.

$ ansible-playbook playbook.yml

PLAY [localhost]
***************************************************************

TASK [Task 1]
******************************************************************
changed: [localhost]

TASK [Task 2]
******************************************************************
skipping: [localhost]

TASK [debug]
*******************************************************************
ok: [localhost] => {
"result": {
"changed": false,
"skip_reason": "Conditional check failed",
"skipped": true
}
}

Is this a bug in Ansible 2.1.1 or is it a new feature?

--
Kai Stian Olstad

Brian Coca

unread,
Sep 12, 2016, 8:33:16 AM9/12/16
to ansible...@googlegroups.com
skipping a task does not skip the registering of variables, as this contains the status of the skipped task for latter testing:

when: result|skipped


----------
Brian Coca

Kai Stian Olstad

unread,
Sep 13, 2016, 4:19:38 AM9/13/16
to ansible...@googlegroups.com
On 12.09.2016 14:33, Brian Coca wrote:
> skipping a task does not skip the registering of variables, as this
> contains the status of the skipped task for latter testing:
>
> when: result|skipped

Thanks Brian.

I'll rewrite my affected roles before upgrade to 2.1.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages