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

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

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.

Hi Kai

All sorted!

Thank you very much!

Regards
JS