AAP - How to copy file from remote server to local AAP

,

Unable to copy files from remote server to local AAP server.

  • Running playbook via AAP (used default execution environments)
  • server 1 - shared files are located (not defined in Inventory)
  • server 2 - target host (defined in inventory)
  • Enabled ssh connection from AAP server with user ‘test’ to server 1 with user ‘ansible’
  • Playbook
- name: Fetch file from remote node
  ansible.builtin.fetch:
    src: /home/ansible/source_file.txt
    dest: /tmp/source_file.txt
    flat: yes
    become_user: ansible
  delegate_to: 'server 1'
  • If I try to change root users to some users for localhost (where my playbook is running), getting below error.
msg: >-
  Failed to change ownership of the temporary files Ansible (via chmod nor
  setfacl) needs to create despite connecting as a privileged user. Unprivileged
  become user would be unable to read the file.
_ansible_no_log: false

I am facing issue to change users for localhost, so that it establish connection to server 1, Otherwise it is failing.

You may want to look at ansible.posix.synchronize with mode: pull. The task definition would be something like this:

- name: Pull files from server 1 to server 2
  ansible.posix.synchronize:
    dest: /place/on/server2
    mode: pull
    src: rsync://server1/path/to/source

This would likely require you to forward an SSH agent with the private key that can access server 1 from server 2. It’s an edge case for the synchronize module but it would allow you to work with a directory if necessary. Otherwise I’d add server 1 to the inventory and have 2 plays, the first uses fetch to get the file(s) you want and the second uses copy to move them to server 2.