Contents

How to config proxy for ansible

Contents

https://statics.lshell.com/logo/Ansible_logo.png

On our server, we need to configure ansible proxy to manage some servers。

We know that the ssh client configures the proxy in this way.

cat ~/.ssh/config 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
Host *  
    User archly  
    StrictHostKeyChecking no  
    TCPKeepAlive yes  
    ConnectTimeout 10  
    Port 22  
    ServerAliveInterval 60  
      # socket 5  
      # ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p  
      # https  
    ProxyCommand nc -X connect -x 127.0.0.1:1081 %h %p

Then, in _/etc/ansible/ansible.cfg _, we can find this:

[ssh_connection]

1
2
3
4
5
# ssh arguments to use  
# Leaving off ControlPersist will result in poor performance, so use  
# paramiko on older platforms rather than removing it, -C controls compression use  
#ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s  
#ControlPersist=60s

So how do you configure ansible?

Just like this:

socket 5

1
ssh_args = -C -o "ProxyCommand=nc -X connect -x 127.0.0.1:1081 %h %p"

Or

1
2
# https  
ssh_args = -C -o "ProxyCommand=nc -X connect -x 127.0.0.1:1081 %h %p"