Copy files with hostname to respective hosts

17 views
Skip to first unread message

Uday Medhi

unread,
May 3, 2018, 6:51:50 AM5/3/18
to Ansible Project
Hi,

I have three files,
host1.zip, host2.zip, host3.zip which are in the ansible server itself in a directory named "deploy".
And I have to copy the files the respective hosts.

host1.zip -----to-----> host1
host2.zip -----to-----> host2
host3.zip -----to-----> host3

I want ansible to look into the directory "deploy", check the files, match it with the hostnames and copy to the respective hosts.

How do I achieve the same ?

Regards,
Uday

Andy Smith

unread,
May 3, 2018, 6:05:12 PM5/3/18
to ansible...@googlegroups.com
Hello,

On Thu, May 03, 2018 at 03:51:50AM -0700, Uday Medhi wrote:
> host1.zip -----to-----> host1
> host2.zip -----to-----> host2
> host3.zip -----to-----> host3
>
> I want ansible to look into the directory "deploy", check the files, match
> it with the hostnames and copy to the respective hosts.
>
> How do I achieve the same ?

How about a simple copy module usage with the ansible_hostname,
inventory_hostname or ansible_nodename facts?

- name: Copy correct zip file to host
copy:
src: "{{ ansible_hostname }}.zip"
dest: /srv/{{ ansible_hostname }}.zip

http://docs.ansible.com/ansible/latest/modules/copy_module.html

http://docs.ansible.com/ansible/latest/modules/setup_module.html

http://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts

Cheers,
Andy
Reply all
Reply to author
Forward
0 new messages