I'm trying to ssh within an ansible task (sounds silly, but is
actually part of a delegate_to in a playbook that streams a backup
from one server to another) but it just hangs.
I've broken it down into simple test case that fails (just hangs and a
^C doesn't kill it) and was hoping someone could help me figure out
why.
I can definitely execute the command (ssh 10.0.1.75 "ls /"') on the
db2 server directly but not using ansible from the control server.
# test.yml
Have you already tried ssh -n?
I think this could fix your problem as you are not running an interactive session.
Thanks for the suggestion, but unfortunately it doesn't work either.
Still hangs in the same spot.
Btw, it also hangs when I use scp.
I changed pty to False in my ansible.cfg and it has fixed the problem.
I feel slightly stupid...
Don’t do this
Use Ansible and if need be, configure jumphosts, or whatever, but Ansible shouldn’t ever NEED to call ssh.
Ansible already has lots of wrappers for that.
A good pattern for checking for SSH being up is using the wait_for module to check if the port is open (usually 22) followed by a pause task of a few seconds to make sure SSHd is ready.
Ready to go!
Don't do this
Use Ansible and if need be, configure jumphosts, or whatever, but Ansible
shouldn't ever *NEED* to call ssh.
I agree it shouldn't be done in general, but I'm interested to see how
you would have solved my initial, more complicated problem. I just
simplified to the smallest thing that had the same symptoms for my
email.
What I was trying to do was run a backup on one server (that may or
may not be managed by ansible) but stream that backup to the ansible
managed server and run some other tasks on it. I think the original
command was something like this:
innobackupex --stream=tar ./ | pigz | ssh user@ansible_host "cat -
/data/backups/backup.tar"
So I don't actually want the backup stored on the delegate server, but
compressed and streamed to the target server that ansible is
controlling.
I thought about using netcat, but that seemed more involved with
having to control it on both ends.
Any other thoughts on how to tackle this?
Ansible already has lots of wrappers for that.
Even though I didn't want to have to write the backup to disk on the
delegate server, I did try to use copy + delegate_to, but now that I
look back, that wasn't going to work.
“I agree it shouldn’t be done in general, but I’m interested to see how
you would have solved my initial, more complicated problem.”
Thanks for providing the actual example of what you are trying to do – this helps us understand more.
I’d probably start by trying to do something with the ‘script’ module and get it to the point where it’s not interactive, and go from there.