0

I have the following task inside an Ansible playbook. I simply want to copy 4 dirs from a remote location (server2) to the same path on the target node (server1)

When running the playbook (using tower) when it reaches this task it just hangs, there is no debug information even on the highest verbosity it only shows tower connecting then nothing further

- name: "Copy files from {{ server2 }}"
  become: "{{ appuser }}"
  shell: "scp -pr {{ appuser }}@{{ server2 }}:{{ item }} {{ item }}"
  with_items:
    - /opt/dir1
    - /opt/some/otherdir
    - /opt/directory
    - /opt/another/folder

to answer expected questions:

  • SSH keys for that user have already been setup on both server1 and server2 and tested and stricthostkey checking is set to no globally
  • Running the scp command manually as the appuser on server1 replacing the variables works perfectly fine
  • Using copy command is not an option as the files are not on the ansible server/tower, only the remote server2, and Synchronize module cannot be used as rsync is not permitted to be installed
  • even when only using 1 item in with_items the issue persists
  • if you dont use variables and just hardcode a regular scp command into the playbook for 1 dir it works fine ( shell: "scp -pr {[email protected]:/path/to/dir/path/to/dir"
  • I have tried using "" on the with_items list didn't make a difference

Additional Notes

only server1 is connected to ansible, server2 is not, it is truely remote, consider it a 3rd party.

5
  • 3
    For sure manually spawning scp from within ansible is a grave antipattern, since (for the very question you're now asking) scp is not designed to be used non-interactively, whereas that is ansible's whole goal in life. Have you perhaps overlooked synchronize:? Commented Mar 8, 2022 at 22:00
  • I've read your requirement "synchronize module cannot be used as rsync is not permitted to be installed", however, an working approach is Ansible Tower - How to copy files from Remote Linux Server1 going to Remote Linux Server2. Commented Mar 9, 2022 at 7:02
  • Regarding your comment "Using copy command is not an option", is there more information why copy with delegate_to and run_once and others is not an option? Commented Mar 9, 2022 at 7:05
  • Is this command run on the right host? I guess this command runs on server2 and then the scp doesn't make sense. Commented Mar 9, 2022 at 7:46
  • Maybe I misunderstand the copy command, I could not find examples of it being used for remotehost to remotehost without the file saving on the ansible server first? I tried and got variations of "file not found" errors only. Could you provide example how to put the destination server in this case? Bare in mind ansible is only aware of server1 so therefore the example link given as a workaround cannot be used. The command is being run with the target node server1 Commented Mar 10, 2022 at 12:05

1 Answer 1

0

This was resolved by removing the -p from scp, I am unsure why this fixed it!

Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.