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

**URL:** <https://forum.ansible.com/t/a-task-is-running-on-a-host-when-it-is-not-meant-to/29089>\
**Category:** Ansible Project\
**Created:** [November 21, 2018, 2:47pm UTC](https://forum.ansible.com/t/a-task-is-running-on-a-host-when-it-is-not-meant-to/29089 "2018-11-21T14:47:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JS11](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@JS11](https://forum.ansible.com/u/JS11)\
**Post date:** [November 21, 2018, 2:47pm UTC](https://forum.ansible.com/t/a-task-is-running-on-a-host-when-it-is-not-meant-to/29089/1 "2018-11-21T14:47:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 21, 2018, 3:08pm UTC](https://forum.ansible.com/t/a-task-is-running-on-a-host-when-it-is-not-meant-to/29089/2 "2018-11-21T15:08:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JS11](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@JS11](https://forum.ansible.com/u/JS11)\
**Post date:** [November 21, 2018, 3:28pm UTC](https://forum.ansible.com/t/a-task-is-running-on-a-host-when-it-is-not-meant-to/29089/3 "2018-11-21T15:28:30Z")

</div>

Hi Kai

All sorted!

Thank you very much!

Regards  
JS
