1

如果有人想尝试,这个问题是可以重现的。

当目标主机“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版本。

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, Sep 26 2019, 13:23:47) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

然后我手动尝试了sshansible输出中的命令,它也冻结了。请参阅下面的 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,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'
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>

我进一步调查并弄清楚如果我 -o ControlPath=/home/ansibleuser/.ansible/cp/6abdc12511 -tt从 ssh 中删除 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,gssapi-keyex,hostbased,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?

4

0 回答 0