Hi everyone,
I need help getting a role to run. Especially the part where one host
has a list of users defined, and the other host has not.
In the host_vars for hostA I have this:
#################
ssh_users:
- foo
- bar
#################
The role main.yml contains:
#################
- name: This runs if ssh_users is not set
copy:
src='{{ ansible_hostname }}'
dest='/some/path/'
when: not ssh_users
- name: This runs if there is a dict called ssh_users
copy:
src='{{ item }}'
dest='/some/path/'
with_items: "{{ ssh_users|default({}) }}"
when: ssh_users
#################
The first part is skipped if ssh_users is set, but returns an error if
it is not set. I think I might be able to use default here somehow,
but haven't figured out how. Using quoted variables does not help either.
For the second part I found out that the with_items is parsed even if
the 'when:' statement would return false, so I get an error. That
should be solvable with default somehow, but I can't get it to do what
I want.
One reason might be that I do not know if ssh_users is a dict or not.
https://docs.ansible.com/ansible/playbooks_conditionals.html
is not clear about this, neither is
https://docs.ansible.com/ansible/playbooks_variables.html#id13
I found this, but I can't adjust it to my case:
https://github.com/ansible/ansible/issues/14448
Any help would be highly appreciated, even a RTFM pointing me to the
right FM would help in this case... ;-)
Thanks,
Johannes