1

How would you, in Ansible, make one remote node connect to another remote node?

My goal is to copy a file from remote node a to remote node b and untar it on the target, however one of the files is extremely large.

So doing it normally via fetching to controller, copy from controller to remote b, then unarchive is unacceptable. Ideally, I would do from _remote_a_ something like:

ssh remote_b cat filename | tar -x

It is to speed things up. I can use shell module to do this, however my main problem is that this way, I lose Ansible's handling of SSH connection parameters. I have to manually pass an SSH private key if any, or password in a non interactive way, or whatever to _remote_b_. Is there any better way to do this without multiple copying?

Also, doing it over SSH is a requirement in this case.

Update/clarification: Actually I know how to do this from shell and I could do same in ansible. I was just wondering if there is a better way to do this that is more ansible-like. The file in question is really large. The main problem is that when ansible executes commands on remote hosts, then I can configure everything in inventory. But in this case, if I would want a similar level of configurability/flexibility when it goes to parameters of that manually established ssh connection I would have to write it from scratch (maybe even as an ansible module), or something similar. Othervise for example trying to just use ssh hostname command would require a passwordless login or default private key, where I wouldn't be able to modify the private key path used in the inventory without adding that manually, and for ssh connection plugin there are actually two possible variables that may be used to set a private key.

Michał Zegan
  • 456
  • 4
  • 12
  • Does this work? https://stackoverflow.com/questions/25505146/how-to-copy-files-between-two-nodes-using-ansible – tink Dec 11 '18 at 23:16
  • https://stackoverflow.com/questions/25505146/how-to-copy-files-between-two-nodes-using-ansible looks like a good fit (needs rsync on both hosts). There is no way around having to manage SSH keys between the two hosts, tho no reason why configuration of those keys could not be handled by Ansible. – clockworknet Dec 12 '18 at 09:55
  • Well, the file is supposed to be untarred after copying. It has 60 gb or so. Note that ssh|tar is far more performant than both rsyncing an expanded form of this, or trying to copy tar then untar separately. and difference could be dramatic. – Michał Zegan Dec 13 '18 at 10:17
  • and we actually have to use a tar instead of copying an expanded form – Michał Zegan Dec 13 '18 at 10:22

1 Answers1

0

Looks like more a shell question than an ansible one. If the 2 nodes cannot talk to each other you can do a

ssh remote_a cat file | ssh remote_b tar xf -

if they can talk (one of the nodes can connect to the other) you can launch tell one remote node to connect to the other, like

ssh remote_b 'ssh remote_a cat file | tar xf -'

(maybe the quoting is wrong, launching ssh under ssh is sometimes confusing). In this last case you need probably to insert some password or set properly public/private ssh keys.

Frediano Ziglio
  • 310
  • 1
  • 6