I'm using ansible to automate some tasks. One of those requires me to ssh to server A, then to B from A and then to C from B. I can't seem to find any way to get ansible to do that. Any suggestions?
相关问题
- Access ansible.cfg variable in task
- JavaScript File Transfer SSH
- Unable to get “exclude” option working with unarch
- Why does this bash script work at console but fail
- Ansible: find file and loop over paths
相关文章
- Check if directory exists on remote machine with s
- Git Clone Fails: Server Certificate Verification F
- Test if File/Dir exists over SSH/Sudo in Python/Ba
- Can't access AWS CodeCommit with SSH
- Sanity check SSH public key? [closed]
- Spark EC2 SSH connection error SSH return code 255
- Use RSA with Eclipse Remote Systems Explorer?
- Ansible create postgresql user with access to all
For Ansible 2.0 and above you can do the following:
Step #1: Edit the
hosts
file and add a line for your target host:Notice the use of the
ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q my-jump-node"'
which handles the proxying through the jump node.Step #2: In the
~/.ssh/config
file define yourmy-jump-node
:Step #3: Notice in step #1 above we have
ansible_ssh_private_key_file=~/.ssh/private_key
. This is the private_key stored at themy-jump-node
and it's corresponding public key is stored atmy-target-host
.The important thing to remember here is:
Step #4: Test it.
Given that you do not use Paramiko for ssh (
transport = ssh
), Ansible will fully use your~/.ssh/config
. Therefore you can globally define all connection rules in your ssh configuration.If for some reason you want Ansible to not use your default ssh config but provide an separate configuration, you can define this in your
ansible.cfg
:In your ssh config then set up the connection rules. To stick with your example: