Contents

[ansible]Ansible with bastian host

How to run ansible commands with servers behind bastian-host

Create ssh custom config file

ssh.config

Host bastion
    HostName               bastian_server_ip
    User                   my_user
    ProxyCommand           none
    IdentityFile           ~/.ssh/id_rsa
    BatchMode              yes
    PasswordAuthentication no
Host *
    ServerAliveInterval    60
    TCPKeepAlive           yes
    ProxyCommand           ssh -q -A my_user@bastian_server_ip nc %h %p
    ControlPath            ~/.ssh/mux-%r@%h:%p
    User                   my_user
    ControlMaster          auto

now we can connect to host behind bastian host with this command :

ssh -F ssh.config host_private_ip

Create ansible custom config file

ansible.cfg

[defaults]
host_key_checking = False
deprecation_warnings = False
[ssh_connection]
ssh_args = -o ControlPersist=15m -F ssh.config -q
scp_if_ssh = True
control_path = ~/.ssh/mux-%%r@%%h:%%p

Run ansible

ansible -a "my_command" all -i host_private_ip,