Skip to content

Instantly share code, notes, and snippets.

@marcinhlybin
Last active May 25, 2018 18:18
Show Gist options
  • Save marcinhlybin/d64d70a3195ac8b1fc694cf46158a83f to your computer and use it in GitHub Desktop.
Save marcinhlybin/d64d70a3195ac8b1fc694cf46158a83f to your computer and use it in GitHub Desktop.
Ansible BUG: include_tasks with loop and when condition
- 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
- debug:
msg: Task is running
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment