ansible -a sudo command hangs

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?

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

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)

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

simplest way would be in inventory
https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#connecting-to-hosts-behavioral-inventory-parameters