you made the default dict, it should be a list
with_items: "{{ ssh_users|default([]) }}"
ssh_users is already a list so no problem there.
On Sun, Mar 6, 2016 at 8:23 AM, Johannes Kastl <[email protected]> wrote:
> 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
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/56DC2F3B.40706%40ojkastl.de
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
----------
Brian Coca
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CACVha7c1sPSP3rKJWAKAD2W_nH_%3DAo8NK%3Dr%2BS0oC0BELP%3DMyqg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.