I assume I'm doing something wrong here, but it would be helpful if someone could at least point me in the right direction. I have the following task:
- name: Set up users
user: name={{ item.username }}
groups={{ item.groups|join(',') }}
comment={{ item.full_name }}
shell=/bin/bash
with_items: "{{ (extra_users is defined) | ternary(users + extra_users, users) }}"
The list extra_users
is only sometimes defined, and when it isn't, the task fails with the error "'extra_users' is undefined"
, which I thought the ternary would guard against. What's going wrong?
I guess that the parameters of the ternary
filter are evaluated no matter what.
Anyway, there is a simplier solution:
with_items: "{{ users | union(extra_users | default ([])) }}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With