ansible填坑记一,UNREACHABLE

本文记录了在生产环境中使用Ansible执行copy操作时遇到的问题及解决方案。由于默认的长连接配置导致连接失败,通过调整ssh_args配置并明确禁用长连接解决了问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天遇到个坑,记录记录.


由于ansible执行copy太慢,想加速下,看文章说使用长连接可以加速,修改配置
/etc/ansible/ansible.cfg
取消此行注释,修改对应长连接时间
ssh_args = -o ControlMaster=auto -o ControlPersist=4h

测试环境用用,no problem

但是放到生产上就报错,并且还原配置都无法解决这个错误...我哪个郁闷,


老办法,出现异常奇葩错误只能祭出仔细分析日志的古法对付.

命令增加参数 -vvv输出更多调试信息

#ansible all -i html/data/tmp/appcheck-host -m shell 'echo 1' -vvv
ansible 2.4.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Nov 20 2015, 02:00:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
Using /etc/ansible/ansible.cfg as config file
Parsed /nginx/html/data/tmp/appcheck-host inventory source with ini plugin
META: ran handlers
Using module file /usr/lib/python2.7/site-packages/ansible/modules/commands/command.py
<10.239.51.139> ESTABLISH SSH CONNECTION FOR USER: ecs
<10.239.51.139> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ecs -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/14e9c7598d 10.239.51.139 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<10.239.51.139> (255, '', 'Control socket connect(/root/.ansible/cp/14e9c7598d): Connection refused\r\nFailed to connect to new control master\r\n')
app9 | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: Control socket connect(/root/.ansible/cp/14e9c7598d): Connection refused\r\nFailed to connect to new control master\r\n", 
    "unreachable": true
}

经过多次分析和搜索ssh的命令行参数,发现

虽然配置中是删除了ssh使用长连接的配置,但是ansible并不认我还原的配置,还是使用长连接...

本来不知为何生产使用长连接报错.配置还原还无效那就坑了


最后解决办法为修改/etc/ansible/ansible.cfg文件中ssh_args配置,显示的指定不使用长连接

ssh_args = -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -C

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值