首页 > 解决方案 > 无法通过 ansible playbook SSH 到远程主机

问题描述

我有两个剧本 Playbook1.yaml 以 root 用户身份安装依赖项并按预期工作,但 playbook2 出现错误。当剧本 1 和 2 的大部分代码相同时,有人可以帮助了解为什么 playbook2 无法运行吗?


Playbook1 yaml 文件

---
- name: Install Cognos Analytics
  hosts: all
  become_method: dzdo
  become_user: root
  become_flags: 'su -'

  tasks:
    - name: Install Cognos Analytics Dependencies
      yum:
        name:
          - java-1.8.0-openjdk
          - glibc.i686
          - glibc.x86_64
          - libstdc++.i686
          - libstdc++.x86_64
          - nspr.i686
          - nspr.x86_64
          - nss.i686
          - nss.x86_64

现在,当我尝试运行时,下面的 Playbook2 yaml 会出现以下错误,有人可以帮我解决这个问题吗?

---
- name: Install Cognos Analytics
  hosts: all
  become_method: dzdo
  become_user: root
  become_flags: 'su -'

 

  tasks:
    - name: Installing Cognos Analytics
      command: /apps/Softwares/ca_instl_lnxi38664_2.0.2003191.bin -f /apps/Softwares/cognosresponsefile.properties -i silent
      args:
        chdir: /apps/SilentInstall

错误日志:

TASK [Installing Cognos Analytics] **************************************************************************************************************************
task path: /etc/ansible/Cognos.yml:9
<10.x.x.x> ESTABLISH SSH CONNECTION FOR USER: jughead
<10.x.x.x> SSH: EXEC sshpass -d8 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'User="jughead"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/a67e55b20e 10.x.x.x '/bin/sh -c '"'"'echo ~jughead && sleep 0'"'"''
<10.x.x.x> (0, '/home/jughead\n', '')
<10.x.x.x> ESTABLISH SSH CONNECTION FOR USER: jughead
<10.x.x.x> SSH: EXEC sshpass -d8 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'User="jughead"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/a67e55b20e 10.x.x.x '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /home/jughead/.ansible/tmp `"&& mkdir "` echo /home/jughead/.ansible/tmp/ansible-tmp-1624909377.53-12390-42703578539020 `" && echo ansible-tmp-1624909377.53-12390-42703578539020="` echo /home/jughead/.ansible/tmp/ansible-tmp-1624909377.53-12390-42703578539020 `" ) && sleep 0'"'"''
<10.x.x.x> (0, 'ansible-tmp-1624909377.53-12390-42703578539020=/home/jughead/.ansible/tmp/ansible-tmp-1624909377.53-12390-42703578539020\n', '')
Using module file /usr/lib/python2.7/site-packages/ansible/modules/commands/command.py
<10.x.x.x> PUT /root/.ansible/tmp/ansible-local-12346tPaVOe/tmpXlWUhD TO /home/jughead/.ansible/tmp/ansible-tmp-1624909377.53-12390-42703578539020/AnsiballZ_command.py
<10.x.x.x> SSH: EXEC sshpass -d8 sftp -o BatchMode=no -b - -C -o ControlMaster=auto -o ControlPersist=60s -o 'User="jughead"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/a67e55b20e '[10.x.x.x]'
<10.x.x.x> (0, 'sftp> put /root/.ansible/tmp/ansible-local-12346tPaVOe/tmpXlWUhD /home/jughead/.ansible/tmp/ansible-tmp-1624909377.53-12390-42703578539020/AnsiballZ_command.py\n', '')
<10.x.x.x> ESTABLISH SSH CONNECTION FOR USER: jughead
<10.x.x.x> SSH: EXEC sshpass -d8 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'User="jughead"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/a67e55b20e 10.x.x.x '/bin/sh -c '"'"'chmod u+x /home/jughead/.ansible/tmp/ansible-tmp-1624909377.53-12390-42703578539020/ /home/jughead/.ansible/tmp/ansible-tmp-1624909377.53-12390-42703578539020/AnsiballZ_command.py && sleep 0'"'"''
<10.x.x.x> (0, '', '')
<10.x.x.x> ESTABLISH SSH CONNECTION FOR USER: jughead
<10.x.x.x> SSH: EXEC sshpass -d8 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'User="jughead"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/a67e55b20e -tt 10.x.x.x '/bin/sh -c '"'"'/usr/bin/python /home/jughead/.ansible/tmp/ansible-tmp-1624909377.53-12390-42703578539020/AnsiballZ_command.py && sleep 0'"'"''
<10.x.x.x> (1, '\r\n{"changed": true, "end": "2021-06-28 15:43:16.115767", "stdout": "", "cmd": ["/apps/Softwares/ca_instl_lnxi38664_2.0.2003191.bin", "-f", "/apps/Softwares/cognosresponsefile.properties", "-i", "silent"], "failed": true, "delta": "0:00:18.049758", "stderr": "", "rc": 255, "invocation": {"module_args": {"creates": null, "executable": null, "_uses_shell": false, "strip_empty_ends": true, "_raw_params": "/apps/Softwares/ca_instl_lnxi38664_2.0.2003191.bin -f /apps/Softwares/cognosresponsefile.properties -i silent", "removes": null, "argv": null, "warn": true, "chdir": "/apps/SilentInstall", "stdin_add_newline": true, "stdin": null}}, "start": "2021-06-28 15:42:58.066009", "msg": "non-zero return code"}\r\n', 'Shared connection to 10.x.x.x closed.\r\n')
<10.x.x.x> Failed to connect to the host via ssh: Shared connection to 10.x.x.x closed.
<10.x.x.x> ESTABLISH SSH CONNECTION FOR USER: jughead
<10.x.x.x> SSH: EXEC sshpass -d8 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'User="jughead"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/a67e55b20e 10.x.x.x '/bin/sh -c '"'"'rm -f -r /home/jughead/.ansible/tmp/ansible-tmp-1624909377.53-12390-42703578539020/ > /dev/null 2>&1 && sleep 0'"'"''
<10.x.x.x> (0, '', '')
fatal: [10.x.x.x]: FAILED! => {
    "changed": true, 
    "cmd": [
        "/apps/Softwares/ca_instl_lnxi38664_2.0.2003191.bin", 
        "-f", 
        "/apps/Softwares/cognosresponsefile.properties", 
        "-i", 
        "silent"
    ], 
    "delta": "0:00:18.049758", 
    "end": "2021-06-28 15:43:16.115767", 
    "invocation": {
        "module_args": {
            "_raw_params": "/apps/Softwares/ca_instl_lnxi38664_2.0.2003191.bin -f /apps/Softwares/cognosresponsefile.properties -i silent", 
            "_uses_shell": false, 
            "argv": null, 
            "chdir": "/apps/SilentInstall", 
            "creates": null, 
            "executable": null, 
            "removes": null, 
            "stdin": null, 
            "stdin_add_newline": true, 
            "strip_empty_ends": true, 
            "warn": true
        }
    }, 
    "msg": "non-zero return code", 
    "rc": 255, 
    "start": "2021-06-28 15:42:58.066009", 
    "stderr": "", 
    "stderr_lines": [], 
    "stdout": "", 
    "stdout_lines": []
}

标签: ansibleansible-2.x

解决方案


认为唯一有意义的是 Playbook 1 以某种方式影响 Playbook 2,我搜索了您的问题并发现了这个:https ://access.redhat.com/solutions/475513 而这个: https: //support.oracle。 com/knowledge/Oracle%20Database%20Products/2543805_1.html

不幸的是,这些都没有提供任何解决方案,而只是提示。假设 NSS 的安装是问题所在,您可以尝试从其日志中找出 sshd 可能失败的原因。


推荐阅读