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 {username@10.10.10.2:/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.

hat
  • 1
  • 2
  • 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:`](https://docs.ansible.com/ansible/2.10/collections/ansible/posix/synchronize_module.html)? – mdaniel Mar 08 '22 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](https://stackoverflow.com/questions/69467057/ansible-tower-how-to-copy-files-from-remote-linux-server1-going-to-remote-linu/69484599#69484599). – U880D Mar 09 '22 at 07: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? – U880D Mar 09 '22 at 07:05
  • Is this command run on the right host? I guess this command runs on server2 and then the scp doesn't make sense. – JGK Mar 09 '22 at 07: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 – hat Mar 10 '22 at 12:05

1 Answers1

0

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

hat
  • 1
  • 2
  • 1
    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](/help/how-to-answer). – Community Mar 10 '22 at 13:13