# ansible -a sudo command hangs

**URL:** <https://forum.ansible.com/t/ansible-a-sudo-command-hangs/36319>\
**Category:** Ansible Project\
**Created:** [February 10, 2022, 7:31pm UTC](https://forum.ansible.com/t/ansible-a-sudo-command-hangs/36319 "2022-02-10T19:31:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [February 10, 2022, 7:31pm UTC](https://forum.ansible.com/t/ansible-a-sudo-command-hangs/36319/1 "2022-02-10T19:31:22Z")

</div>

I am trying to run remote commands on few servers

ansible -a “df -h” myservers -i hosts -u “user” --assk-pass

this works

but when i do

ansible -a “sudo systemctl status docker” -i hosts -u "user --ask-pass

then i enter my password

it just hangs

any idea?

---

<div class="post-metadata">

**Author:** ![Alex\_Wanderley](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alex_wanderley/32/3232_2.png) [@Alex\_Wanderley](https://forum.ansible.com/u/Alex_Wanderley)\
**Post date:** [February 10, 2022, 8:41pm UTC](https://forum.ansible.com/t/ansible-a-sudo-command-hangs/36319/2 "2022-02-10T20:41:57Z")

</div>

Hello,

Yes, I have a clue: check your sudo configuration.  
Very likely your sudo is set up in a way it is requiring an TTY for command executions. When Ansible sends a command it uses ssh, which usually does not provide a TTY.

Alex

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 10, 2022, 10:55pm UTC](https://forum.ansible.com/t/ansible-a-sudo-command-hangs/36319/3 "2022-02-10T22:55:06Z")

</div>

try this instead:

ansible -a “systemctl status docker” -i hosts -u user --ask-pass -K --become

Adding (–become) makes ansible responsible for executing sudo (default become method) and passing in a password if needed (-K prompts you ahead of time for the sudo password)

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [February 11, 2022, 2:00pm UTC](https://forum.ansible.com/t/ansible-a-sudo-command-hangs/36319/4 "2022-02-11T14:00:30Z")

</div>

thank you. that works.

how do i save the users password and the become pass?

like I want to run

ansible -a “systemctl status docker” myhosts -i hosts --become

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 11, 2022, 7:35pm UTC](https://forum.ansible.com/t/ansible-a-sudo-command-hangs/36319/5 "2022-02-11T19:35:36Z")

</div>

simplest way would be in inventory  
[https://docs.ansible.com/ansible/latest/user\_guide/intro\_inventory.html#connecting-to-hosts-behavioral-inventory-parameters](https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#connecting-to-hosts-behavioral-inventory-parameters)
