A task is running on a host when it is not meant to

9 views
Skip to first unread message

JS

unread,
Nov 21, 2018, 9:47:52 AM11/21/18
to Ansible Project
Hello everyone!

I have a task defined below, that only needs to run on the hosts that are within the bastion-hosts group. However, it is also running on hosts that are not in the group bastion-hosts.

- name: Fetch user's public cloud key for deploy to internal hosts later
  fetch:
    src: "{{ item.home | default(users_home ~ '
/' ~ item.username) }}/.ssh/id_{{ item.ssh_key_type | default('rsa') }}.pub"
    dest: {{ files_bastion_cloud_keys_path }}/id_{{ item.ssh_key_type | default('
rsa') }}-{{ item.username }}.pub
    flat: yes
  when: ("'
bastion-hosts' in group_names") and (item.ssh_key_generate is defined) and item.ssh_key_generate
  with_items: "{{ users }}"

Could you kindly advise where I might be going wrong?

Regards
JS

Kai Stian Olstad

unread,
Nov 21, 2018, 10:09:03 AM11/21/18
to ansible...@googlegroups.com
On Wednesday, 21 November 2018 15:47:51 CET JS wrote:
> when: ("'bastion-hosts' in group_names") and (item.ssh_key_generate is defined) and item.ssh_key_generate

Because of you double quotes everything in between the parenthesis is considered a string and not an expression.
Remove the double quotes and it should work.

--
Kai Stian Olstad


JS

unread,
Nov 21, 2018, 10:28:30 AM11/21/18
to Ansible Project
Hi Kai

All sorted!

Thank you very much!

Regards
JS
Reply all
Reply to author
Forward
0 new messages