Question:
Ansible 1.9.4.
The script should execute some task only on hosts where some variable is defined. It works fine normally, but it doesn’t work with the with_items
statement.
1 2 3 4 5 6 7 8 |
- debug: var=symlinks when: symlinks is defined - name: Create other symlinks file: src={{ item.src }} dest={{ item.dest }} state=link with_items: "{{ symlinks }}" when: symlinks is defined |
But I get:
1 2 3 4 5 6 |
TASK: [app/symlinks | debug var=symlinks] ********************* skipping: [another-host-yet] TASK: [app/symlinks | Create other symlinks] ****************** fatal: [another-host-yet] => with_items expects a list or a set |
Maybe I am doing something wrong?
Answer:
1 2 |
with_items: "{{ symlinks | default([]) }}" |