ansible填坑记一,UNREACHABLE

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


由于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

你可能感兴趣的:(ansible)