# copy file to one host only

**URL:** <https://forum.ansible.com/t/copy-file-to-one-host-only/36819>\
**Category:** Ansible Project\
**Created:** [July 8, 2022, 4:34pm UTC](https://forum.ansible.com/t/copy-file-to-one-host-only/36819 "2022-07-08T16:34:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [July 8, 2022, 4:34pm UTC](https://forum.ansible.com/t/copy-file-to-one-host-only/36819/1 "2022-07-08T16:34:33Z")

</div>

I am trying to copy a file to one host. the file will be on my ansible host I am copying over to the remote host

do I need to create a file folder and put the file I want copied there

project  
├── hosts  
├── main.yml  
└── roles  
└── poc  
├── **files**  
│ └── **cluster.yml**  
├── tasks  
│ └── main.yml  
└── vars  
└── main.yml

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [July 8, 2022, 4:53pm UTC](https://forum.ansible.com/t/copy-file-to-one-host-only/36819/2 "2022-07-08T16:53:38Z")

</div>

Your question is a little vague without invoking the “read-my-mind” module.  
If you’re talking about on the Ansible controller, you already have the file in a director: roles/poc/files/cluster.yml  
If you’re asking about on the target host, if the directory already exists, you can just copy it with the copy module. Otherwise you’ll need to use the file module to ensure the target directory exists before you can copy it there.

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [July 8, 2022, 4:58pm UTC](https://forum.ansible.com/t/copy-file-to-one-host-only/36819/3 "2022-07-08T16:58:32Z")

</div>

Thank you here is a snippet and it works fine with the file in the file folder structure

- name: copy cluster file to jumphost  
become: true  
copy:  
src: “cluster.yml”  
dest: “/home/rke”  
owner: “{{ username }}”  
group: “{{ username }}”  
mode: ‘0644’

but I want to only run this on a single host and not all hosts.

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [July 8, 2022, 5:23pm UTC](https://forum.ansible.com/t/copy-file-to-one-host-only/36819/4 "2022-07-08T17:23:36Z")

</div>

keep getting this

ERROR! conflicting action statements: hosts, copy

when I add

hosts: gui

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [July 8, 2022, 6:03pm UTC](https://forum.ansible.com/t/copy-file-to-one-host-only/36819/5 "2022-07-08T18:03:08Z")

</div>

At the same indentation level as “copy:”, you want something like  
when: ansible\_host == gui

Or, if “gui” is a group  
when: “‘gui’ in group\_names”

The “w” of “when” and the “c” of “copy” should be in the same column.
