Shy*_*Jos 0 linux ssh bash ansible
我们在 DC 中有几台未连接到互联网的服务器(只能通过 vpn 访问),有时我们需要使用 htpdate 更新服务器中的时间,现在我们通过创建 ssh 隧道和鱿鱼代理来完成(请参阅下面的命令) )
ssh root@192.168.30.10 -R3128:localhost:3128
export http_proxy='http://localhost:3128'
htpdate -da -l -P localhost:3128 3.in.pool.ntp.org 1.asia.pool.ntp.org 3.asia.pool.ntp.org
export http_proxy=' '
Run Code Online (Sandbox Code Playgroud)
如何使用 ansible 自动执行此操作?
您可以通过ansible_ssh_extra_args或同伴添加任何 SSH 参数(请参阅文档)。
存货:
remote-host ansible_host=192.168.30.10 ansible_ssh_extra_args="-R3128:localhost:3128"
Run Code Online (Sandbox Code Playgroud)
剧本:
- hosts: remote-host
environment:
http_proxy: http://localhost:3128
tasks:
- command: htpdate -da -l -P localhost:3128 3.in.pool.ntp.org 1.asia.pool.ntp.org 3.asia.pool.ntp.org
Run Code Online (Sandbox Code Playgroud)