Sudo: timed out reading password error

shell module hangs and fails with timed out reading password error.

  • I am trying to run a command that requires sudo, I could run manually and it works fine.
  • when tried to run from the shell module, the tasks hangs and fails with timed out reading password error.
  • provided below the playbook used and the error response.
  • playbook used
- name: Get machine info.
  vars:
    ansible_python_interpreter: /usr/bin/python
  hosts:  all
  gather_facts: yes
  tasks:
    - name: Run pvs command
      shell: |
        sudo pvs

ansible command used:

ansible-playbook com.yml -i hosts -u rmdev -k -K


Error response: 
fatal: [swhdev3456]: FAILED! => {
    "changed": true,
    "cmd": "echo \"---------------------- date --------------------------------\"\nsudo pvs\n",
    "delta": "0:05:02.321612",
    "end": "2025-08-14 07:58:17.859787",
    "invocation": {
        "module_args": {
            "_raw_params": "echo \"---------------------- date --------------------------------\"\nsudo pvs\n",
            "_uses_shell": true,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true,
            "warn": false
        }
    },
    "msg": "non-zero return code",
    "rc": 1,
    "start": "2025-08-14 07:53:15.538175",
    "stderr": "sudo: timed out reading password\nsudo: a password is required",
    "stderr_lines": [
        "sudo: timed out reading password",
        "sudo: a password is required"
    ],
    "stdout": "---------------------- date --------------------------------",
    "stdout_lines": [
        "---------------------- date --------------------------------"
    ]
}



I updated the playbook like this, but still same error

- name: Get machine info.
  vars:
    ansible_python_interpreter: /usr/bin/python
  hosts:  all
  gather_facts: yes
  become: yes
  become_user: rmdev
  become_method: sudo
  tasks:
    - name: Run pvs command
      shell: |
        sudo pvs

how to fix this issue?

Thanks,

Mohan

The option -K quote: “ask for privilege escalation password”. SeeUnderstanding privilege escalation: become. Instead of executing sudo in the command, escalate the privilege on the task level

- name: Run pvs command
  become: true
  shell: pvs

Then, the option -K works as expected.

Note: The option -k quote: “ask for connection password” has nothing to do with the escalation.

1 Like
Thanks vbotka 

I updated the playbook as

- name: Get machine info.
  vars:
    ansible_python_interpreter: /usr/bin/python
  hosts:  all
  gather_facts: yes
  tasks:
    - name: Run pvs command
      shell: pvs
      become: true

now getting below error

fatal: [swhdev3456]: FAILED! => {
    "changed": false,
    "module_stderr": "Shared connection to swhdev3456 closed.\r\n",
    "module_stdout": "\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

This is a connection problem. See man ansible-playbook :

-v, --verbose
   ... connection debugging might require -vvvv.
2 Likes
with -vvvv
fatal: [swhdev3456]: FAILED! => {
    "changed": false,
    "module_stderr": "OpenSSH_8.0p1, OpenSSL 1.1.1k  FIPS 25 Mar 2021\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug3: /etc/ssh/ssh_config line 52: Including file /etc/ssh/ssh_config.d/05-redhat.conf depth 0\r\ndebug1: Reading configuration data /etc/ssh/ssh_config.d/05-redhat.conf\r\ndebug2: checking match for 'final all' host swhdev3456 originally swhdev3456\r\ndebug3: /etc/ssh/ssh_config.d/05-redhat.conf line 3: not matched 'final'\r\ndebug2: match not found\r\ndebug3: /etc/ssh/ssh_config.d/05-redhat.conf line 5: Including file /etc/crypto-policies/back-ends/openssh.config depth 1 (parse only)\r\ndebug1: Reading configuration data /etc/crypto-policies/back-ends/openssh.config\r\ndebug3: gss kex names ok: [gss-curve25519-sha256-,gss-nistp256-sha256-,gss-group14-sha256-,gss-group16-sha512-,gss-gex-sha1-,gss-group14-sha1-]\r\ndebug3: kex names ok: [curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1]\r\ndebug1: configuration requests final Match pass\r\ndebug1: re-parsing configuration\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug3: /etc/ssh/ssh_config line 52: Including file /etc/ssh/ssh_config.d/05-redhat.conf depth 0\r\ndebug1: Reading configuration data /etc/ssh/ssh_config.d/05-redhat.conf\r\ndebug2: checking match for 'final all' host swhdev3456 originally swhdev3456\r\ndebug3: /etc/ssh/ssh_config.d/05-redhat.conf line 3: matched 'final'\r\ndebug2: match found\r\ndebug3: /etc/ssh/ssh_config.d/05-redhat.conf line 5: Including file /etc/crypto-policies/back-ends/openssh.config depth 1\r\ndebug1: Reading configuration data /etc/crypto-policies/back-ends/openssh.config\r\ndebug3: gss kex names ok: [gss-curve25519-sha256-,gss-nistp256-sha256-,gss-group14-sha256-,gss-group16-sha512-,gss-gex-sha1-,gss-group14-sha1-]\r\ndebug3: kex names ok: [curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1]\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 4 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 = 152294\r\ndebug3: mux_client_request_session: session request sent\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\nShared connection to swhdev3456 closed.\r\n",
    "module_stdout": "\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Your mux session is losing connection. To proceed, try to isolate the Ansible problem, if any, and provide Minimal reproducible example.

FYI, fact gathering already gathers LVM information

1 Like

with -c paramiko, I could identify that my user does have permission to run the Ansible python script as root user. I wonder why openssh error were not clear.
thanks for all the troubleshooting help.

Sorry, user rmdev is not allowed to execute '/bin/sh -c echo BECOME-SUCCESS-asdfewqvocjyxzasddoikqezkdsseijok ; /usr/bin/python /home/rmdev/.ansible/tmp/ansible-tmp-1755186449.9872587-12357-118527423543084/AnsiballZ_command.py' as root on swhdev3456.