copy file to one host only

19 views
Skip to first unread message

Tony Wong

unread,
Jul 8, 2022, 12:34:33 PM7/8/22
to Ansible Project
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

Todd Lewis

unread,
Jul 8, 2022, 12:53:38 PM7/8/22
to Ansible Project
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.

Tony Wong

unread,
Jul 8, 2022, 12:59:02 PM7/8/22
to ansible...@googlegroups.com
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. 



--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/PUJL9ortatY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c2989980-f6ee-4bc8-b26b-dec49a78d2b5n%40googlegroups.com.

Tony Wong

unread,
Jul 8, 2022, 1:24:05 PM7/8/22
to ansible...@googlegroups.com
keep getting this

ERROR! conflicting action statements: hosts, copy

when I add 

hosts: gui

Todd Lewis

unread,
Jul 8, 2022, 2:03:08 PM7/8/22
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages