Ansible playbook copy failed - msg: could not find src

11,533

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

remote_src: yes

Share:
11,533
Ann
Author by

Ann

Updated on June 04, 2022

Comments

  • Ann
    Ann almost 2 years

    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