Luis Henrique
Luis Henrique

Reputation: 771

Failed to copy file from host to ansible server

I'm trying to do a simple process with ansible, however I get failed when trying to run this playbook, I would just like to take the existing file in the user's temporary directory and copy it back to the ansible server inside etc/ansible/files

path and permissions

root@ansible:/etc/ansible/files# pwd
/etc/ansible/files
root@ansible:/etc/ansible/files# ls -ltr ../
total 24
-rw-r--r-- 1 root root  535 mar 27 11:23 ansible.cfg
-rw-r--r-- 1 root root  188 mar 27 15:41 hosts
drwxr-xr-x 5 root root 4096 mar 27 15:42 roles
drwxr-xr-x 2 root root 4096 mar 27 15:42 group_vars
drwxrwxrwx 2 root root 4096 mar 27 16:59 files
drwxr-xr-x 3 root root 4096 mar 27 17:01 playbook

playbook

- name: auto_collect_pingprobe
  hosts: "{{ affected_host }}"
  gather_facts: no
  tasks:
    - block:

        - name: 'Copy net connect'
          fetch:
            src: '%temp%\net_connect.cfg'
            dest: '/etc/ansible/files/net_connect.cfg'
            flat: yes

      rescue:
        - fail:
            msg: "Failure detected in playbook"

output

fatal: [192.168.238.12]: FAILED! => {
    "msg": "failed to transfer file to \"/etc/ansible/files/net_connect.cfg\""
}

TASK [fail] *************************************************************************************************************************************************
task path: /etc/ansible/playbook/GEN_AUTO_COLLECT_HOST_AVAILABLE.yml:22
fatal: [192.168.238.12]: FAILED! => {
    "changed": false,
    "msg": "Failure detected in playbook"
}

Upvotes: 0

Views: 1004

Answers (1)

SpaceKatt
SpaceKatt

Reputation: 1411

Two things may be going on.

  1. You may not have root permissions on the controlled node, ensure that you are using the --become flag when invoking the notebook (or use equivalent privilege escalation).
  2. The %temp% variable may not be being read from the environment. Try replacing the src string with '{{ lookup("env", "temp") }}\net_connect.cfg'.

Upvotes: 1

Related Questions