Ansible 错误与 myhost1 的共享连接已关闭。使用原始模块时

Ansible error Shared connection to myhost1 closed. when using raw module

我的ansible目标服务器是SunOS。

我在使用原始模块时收到 Ansible 错误 Shared connection to myhost1 closed.

当我将模块更改为 shell 时,错误不会显示,但是,脚本 start.sh 的执行不会发生(从 ps 命令中可以看出)因此我希望使用 raw

- name: "START ADP SERVICES"
  raw: "source ~/.profile; sh /web/external_products/springboot/{{ vars[ environ + '_folder'] }}/veladpservice/bin/start.sh veladpservice.jar {{ vars[ environ + '_folder'] }} {{ allpass }}"

使用shell模块时的输出:

TASK [START ADAPTER SERVICES] **************************************************
task path: /web/playbooks/automation/veladp/va_action.yml:32
changed: [myhost1] => {"changed": true, "cmd": "source ~/.profile; sh /web/external_products/springboot/stg/veladpservice/bin/start.sh veladpservice.jar stg WEB_USER apps_user_2021_2378 MSPW435 MSPW435 MSPW445 MSPW445 PETWEB440 Temp_45678 MSPW460 Temp_3456789012 MSPW430 Temp_1234567890 MSPW455 Temp_09876", "delta": "0:00:01.009433", "end": "2021-10-28 05:47:51.277868", "rc": 0, "start": "2021-10-28 05:47:50.268435", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

使用raw模块时:

TASK [START adp SERVICES] *********************************************************************************
task path: /web/playbooks/automation/veladprestart/va_action.yml:32
<myhost1> ESTABLISH SSH CONNECTION FOR USER: myuser1
<myhost1> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="myuser1"' -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ControlPath=/home/myuser1/.ansible/cp/cc89a5347e -tt myhost1 'source ~/.profile; /web/external_products/springboot/stg/veladpservice/bin/start.sh veladpservice.jar stg MSP_WEB_USER Marsh_apps_user_2021_2378 MSPW435 MSPW435 MSPW445 MSPW445 PETWEB440 Temp_345678 MSPW460 Temp_3456789012 MSPW430 Temp_1234567890 MSPW455 Temp_0987654321'
<myhost1> (0, b'', b"OpenSSH_8.4p1 (CentrifyDC build 5.7.1-346) , OpenSSL 1.1.1g  21 Apr 2020\r\ndebug1: Reading configuration data /etc/centrifydc/ssh/ssh_config\r\ndebug1: /etc/centrifydc/ssh/ssh_config line 3: Applying options for *\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/myuser1/.ssh/known_hosts'\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/myuser1/.ssh/known_hosts2'\r\ndebug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 21893\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to myhost1 closed.\r\n")
changed: [myhost1] => {
    "changed": true,
    "rc": 0,
    "stderr": "OpenSSH_8.4p1 (CentrifyDC build 5.7.1-346) , OpenSSL 1.1.1g  21 Apr 2020\r\ndebug1: Reading configuration data /etc/centrifydc/ssh/ssh_config\r\ndebug1: /etc/centrifydc/ssh/ssh_config line 3: Applying options for *\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/myuser1/.ssh/known_hosts'\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/myuser1/.ssh/known_hosts2'\r\ndebug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 21893\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to myhost1 closed.\r\n",
    "stderr_lines": [
        "OpenSSH_8.4p1 (CentrifyDC build 5.7.1-346) , OpenSSL 1.1.1g  21 Apr 2020",
        "debug1: Reading configuration data /etc/centrifydc/ssh/ssh_config",
        "debug1: /etc/centrifydc/ssh/ssh_config line 3: Applying options for *",
        "debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/myuser1/.ssh/known_hosts'",
        "debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/myuser1/.ssh/known_hosts2'",
        "debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling",
        "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 = 21893",
        "debug3: mux_client_request_session: session request sent",
        "debug1: mux_client_request_session: master session id: 2",
        "debug3: mux_client_read_packet: read header failed: Broken pipe",
        "debug2: Received exit status from master 0",
        "Shared connection to myhost1 closed."
    ],
    "stdout": "",
    "stdout_lines": []
}

更新post建议:

我也尝试使用 disown 分离进程,如下所示,但 ps 仍然没有显示进程 运行:

- name: "START ADAPTER SERVICES"
  shell: "source ~/.profile && sh /web/external_products/springboot/{{ vars[ environ + '_folder'] }}/velocityadapterservice/bin/start.sh velocityadapterservice.jar {{ vars[ environ + '_folder'] }} {{ allpass }} &; disown %%"

~/.profile & start.sh 但拥有 744 权限并且所有者是 myuser1

注意:运行与手动操作相同的过程!!

你能推荐一下吗?

@mdaniel 的建议给了我线索。但是,nohup 帮助解决了问题,但仍然不确定 disown。下面是解决方法。

- name: "START ADAPTER SERVICES"
  shell: "source ~/.profile && nohup /web/external_products/springboot/{{ vars[ environ + '_folder'] }}/velocityadapterservice/bin/start.sh velocityadapterservice.jar {{ vars[ environ + '_folder'] }} {{ allpass }} &"