Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible playbook copy failed - msg: could not find src

Tags:

file

copy

ansible

I am new to ansible and I am trying to clopy a file from one directory to another directory on a remote RH machine using ansible.

---
- hosts: all
  user: root
  sudo: yes
  tasks:

  - name: touch
    file: path=/home/user/test1.txt state=touch

  - name: file
    file: path=/home/user/test1.txt mode=777

  - name: copy
    copy:  src=/home/user/test1.txt dest=/home/user/Desktop/test1.txt

But it throws error as below

[root@nwb-ansible ansible]# ansible-playbook a.yml -i hosts 
SSH password: 

PLAY [all] ******************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [auto-0000000190]

TASK: [touch] ***************************************************************** 
changed: [auto-0000000190]

TASK: [file] ****************************************************************** 
ok: [auto-0000000190]

TASK: [copy] ****************************************************************** 
failed: [auto-0000000190] => {"failed": true}
msg: could not find src=/home/user/test1.txt

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/root/a.retry

auto-0000000190            : ok=3    changed=1    unreachable=0    failed=1   

[root@nwb-ansible ansible]# 

The file has created in the directory and both the file and the directory has got permissions 777.

I am getting the same error message if I try to just copy already existing file using ansible.

I have tried as non-root user as well but no success.

Thanks a lot in advance,

Angel

like image 251
Ann Avatar asked Oct 29 '25 20:10

Ann


1 Answers

Luckily this is a simple fix, all you need to do after the copy is add

remote_src: yes

like image 165
Namit Agarwal Avatar answered Oct 31 '25 10:10

Namit Agarwal