Home > Software design >  Ansible error Shared connection to myhost1 closed. when using raw module
Ansible error Shared connection to myhost1 closed. when using raw module

Time:10-30

My ansible target server is SunOS.

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

The error does not show when i change module to shell however, the execution of script start.sh does not happen (evident from outout of ps command) hence i wish to use 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 }}"

Output when using shell module:

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": []}

When using raw module:

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": []
}

Update post suggestion:

I also tried detaching the process using disown like below but the ps still does not show the process running:

- 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 but have 744 permissions and the owner is myuser1

Note: Running the same process as is manually works!!

Can you please suggest?

CodePudding user response:

@mdaniel suggestion gave me the clue. However, nohup helped resolve the issue and still not sure about disown. Below is the solution.

- 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 }} &"
  • Related