微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

未找到python解释器时,Ansible播放挂起冻结

如何解决未找到python解释器时,Ansible播放挂起冻结

如果有人想尝试,可以重现此问题。

当目标主机“ 10.9.88.205”未安装python时,Ansible挂起。

我从ansible到目标主机成功建立了ssh连接,如下所示:

ansible-host# ssh root@10.9.88.205

下面是我的剧本:

- name: Play 2- Configure Source nodes
  hosts: all
  user: root
  ignore_errors: yes
  gather_facts: false
  tasks:

   - name: Get HTTPD userid on server
     raw: id mwweb || id webadm || ls -ld /web

   - name: Get OHS userid on server
     raw: id mwweb

下面是我运行剧本的方式

[ansibleuser@ansiblehost checkssh]$ ansible-playbook -i 10.9.88.205,-f 5 testpython.yml -vvvv
ansible-playbook 2.9.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/ansibleuser/.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-playbook
  python version = 2.7.5 (default,Sep 26 2019,13:23:47) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
Parsed 10.9.88.205,inventory source with host_list plugin
Loading callback plugin default of type stdout,v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/default.pyc

PLAYBOOK: testpython.yml ***********************************************************************************************************************************************
Positional arguments: testpython.yml
become_method: sudo
inventory: (u'10.9.88.205,',)
forks: 5
tags: (u'all',)
verbosity: 4
connection: smart
timeout: 10
1 plays in testpython.yml

PLAY [Play 2- Configure Source nodes] **********************************************************************************************************************************
Meta: ran handlers

TASK [Get HTTPD userid on server] **************************************************************************************************************************************
task path: /app/axmw/Ansible/playbook/checkssh/testpython.yml:24
<10.9.88.205> ESTABLISH SSH CONNECTION FOR USER: root
<10.9.88.205> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/app/ssh_keys/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ControlPath=/home/ansibleuser/.ansible/cp/6abdc12511 -tt 10.9.88.205 'id mwweb || id webadm || ls -ld /web'

它仅在打印TASK [Get HTTPD userid on server] 后挂起,并且从未完成。

所有未安装python且可通过ssh访问的IP都会遇到这种情况。

更新:下面的调查是用户@larsks的后期调试建议

下面是我的烦人的版本。

ansible --version
ansible 2.9.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/.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,13:23:47) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

然后,我从ansible输出中手动尝试了ssh命令,该命令也冻结了。请参阅下面的ssh输出

[ansibleuser@ansiblehostcheckssh]$ ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/app/ssh_keys/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ControlPath=/home/ansibleuser/.ansible/cp/6abdc12511 -tt 10.9.88.205 'id mwweb || id webadm || ls -ld /web'
OpenSSH_7.4p1,OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: auto-mux: Trying existing master
debug2: fd 3 setting O_NONBLOCK
debug2: mux_client_hello_exchange: master version 4
debug3: mux_client_forwards: request forwardings: 0 local,0 remote
debug3: mux_client_request_session: entering
debug3: mux_client_request_alive: entering
debug3: mux_client_request_alive: done pid = 70199
debug3: mux_client_request_session: session request sent

<Freezes Hangs after this>

我进一步调查并确定了是否从ssh中删除 -o ControlPath=/home/ansibleuser/.ansible/cp/6abdc12511 -tt,表明ansible构造了ssh可以正常工作并且不会挂起。

因此,下面手动构造的ssh可以正常工作。

ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/app/ssh_keys/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o StrictHostKeyChecking=no 10.9.88.205 'id mwweb || id webadm || ls -ld /web'

您能建议我如何使自己不挂死并继续执行下一个任务吗?

Get OHS userid on server

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。