remote1 ->fetch-> control machine ->copy-> remote2

18 views
Skip to first unread message

Bond James

unread,
May 25, 2021, 4:14:34 AM5/25/21
to Ansible Project

Hello!

I have 2 remote hosts and 1 master node with my playbooks. I want that file with name ".env" was copy with module "Fetch" to Master node and then, with module "copy" will copy to Remote host 2

hosts:

[jitsi]
185.139.68.189

[VideoBridge2]
46.17.104.103

[Jitsi_Stack]
185.139.68.189
46.17.104.103

[jitsi:vars]
ansible_python_interpreter=/usr/bin/python3

[VideoBridge2:vars]
ansible_python_interpreter=/usr/bin/python3

My playbook:

---
hostsJitsi_Stack
  tasks:

    - namefetch /home/docker-jitsi-meet/.env
      fetch:
        src/home/docker-jitsi-meet/.env
        dest/home/
        flattrue
        wheninventory_hostname == "185.139.68.189"

    - nameCopy the file from master to VideoBridge2
      copy:
        src/home/.env
        dest/home/
        wheninventory_hostname == "46.17.104.103"

But it does not work:

root@lxd02:/etc/ansible/playbook/VideoBridges# ansible-playbook -vv File_copy_from_host_to_host.yaml
ansible-playbook 2.9.6
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0]
Using /etc/ansible/ansible.cfg as config file

PLAYBOOK: File_copy_from_host_to_host.yaml **************************************************************************
1 plays in File_copy_from_host_to_host.yaml

PLAY [Jitsi_Stack] **************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************
task path: /etc/ansible/playbook/VideoBridges/File_copy_from_host_to_host.yaml:2
ok: [185.139.68.189]
ok: [46.17.104.103]
META: ran handlers

TASK [fetch /home/docker-jitsi-meet/.env] ***************************************************************************
task path: /etc/ansible/playbook/VideoBridges/File_copy_from_host_to_host.yaml:6
changed: [185.139.68.189] => {"changed": true, "checksum": "b445c33c0e4e59ef8624d22060cdbeb1e8953a86", "dest": "/home/.env", "md5sum": "89718e47f6f1fa3817a707f88e7c3774", "remote_checksum": "b445c33c0e4e59ef8624d22060cdbeb1e8953a86", "remote_md5sum": null}
fatal: [46.17.104.103]: FAILED! => {"changed": false, "msg": "file not found: /home/docker-jitsi-meet/.env"}

TASK [Copy the file from master to VideoBridge2] ********************************************************************
task path: /etc/ansible/playbook/VideoBridges/File_copy_from_host_to_host.yaml:13
ok: [185.139.68.189 -> localhost] => {"changed": false, "checksum": "b445c33c0e4e59ef8624d22060cdbeb1e8953a86", "dest": "/home/.env", "gid": 0, "group": "root", "mode": "0644", "owner": "root", "path": "/home/.env", "size": 10437, "state": "file", "uid": 0}
META: ran handlers
META: ran handlers

PLAY RECAP **********************************************************************************************************
185.139.68.189             : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
46.17.104.103              : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0 

Could you please help to solve this issue?

Rodrigues -

unread,
May 25, 2021, 5:08:13 PM5/25/21
to Ansible Project
The issue is that it cannot find the files as it's expecting a single file which name is ".env"
If you want to copy all files with that extension you may need a different solution. Have a look here: https://stackoverflow.com/questions/54152051/ansible-fetch-a-collection-of-files-to-the-destination-without-copying-remote
Reply all
Reply to author
Forward
0 new messages