Last active
May 25, 2018 18:18
-
-
Save marcinhlybin/d64d70a3195ac8b1fc694cf46158a83f to your computer and use it in GitHub Desktop.
Ansible BUG: include_tasks with loop and when condition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: localhost | |
gather_facts: false | |
vars: | |
# default_state: absent | |
tasks: | |
- name: task1 | |
- name: task2 | |
tasks: | |
- debug: | |
var: task.state | default(default_state) | |
loop: "{{ tasks }}" | |
loop_control: | |
label: item.name | |
loop_var: task | |
- include_tasks: tasks.yml | |
loop: "{{ tasks }}" | |
loop_control: | |
label: item.name | |
loop_var: task | |
when: task.state | default(default_state) == 'present' | |
Output. Tasks are running but shouldn't: null == 'present'? | |
PLAY [localhost] ********************************************************************************************************************************************** | |
TASK [debug] ************************************************************************************************************************************************** | |
ok: [localhost] => (item=item.name) => { | |
"task": { | |
"name": "task1" | |
}, | |
"task.state | default(default_state)": "VARIABLE IS NOT DEFINED!" | |
} | |
ok: [localhost] => (item=item.name) => { | |
"task": { | |
"name": "task2" | |
}, | |
"task.state | default(default_state)": "VARIABLE IS NOT DEFINED!" | |
} | |
TASK [include_tasks] ****************************************************************************************************************************************** | |
included: playbooks/tasks.yml for localhost | |
included: playbooks/tasks.yml for localhost | |
TASK [debug] ************************************************************************************************************************************************** | |
ok: [localhost] => { | |
"msg": "Task is running" | |
} | |
TASK [debug] ************************************************************************************************************************************************** | |
ok: [localhost] => { | |
"msg": "Task is running" | |
} | |
PLAY RECAP **************************************************************************************************************************************************** | |
localhost : ok=5 changed=0 unreachable=0 failed=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- debug: | |
msg: Task is running |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment