# Ask sudo password only when needed

**URL:** <https://forum.ansible.com/t/ask-sudo-password-only-when-needed/14089>\
**Category:** Ansible Project\
**Created:** [December 6, 2013, 10:14am UTC](https://forum.ansible.com/t/ask-sudo-password-only-when-needed/14089 "2013-12-06T10:14:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anatoly\_techtonik](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@anatoly\_techtonik](https://forum.ansible.com/u/anatoly_techtonik)\
**Post date:** [December 6, 2013, 10:14am UTC](https://forum.ansible.com/t/ask-sudo-password-only-when-needed/14089/1 "2013-12-06T10:14:25Z")

</div>

Hi,

Can Ansible check that current sudo is active?

Right now it supports two modes:

1. Never asking password
2. Asking password every time

On my system, after I enter sudo pass, systems stops asking for sudo password for other commands for a few minutes. Is it possible to implement the same behavior in Ansible?

Right now I am executing `sudo ansible-playbook`, which makes fine-grained per-task `sudo:` entries somewhat pointless.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 6, 2013, 1:17pm UTC](https://forum.ansible.com/t/ask-sudo-password-only-when-needed/14089/2 "2013-12-06T13:17:25Z")

</div>

It’s totally not pointless.

If you sudo ansible, you are running ansible as root locally.

It sounds like you aren’t managing any remote systems in your case, so you’re in a minority use case.

Ansible is designed around managing remote systems, where sudo’ing ansible itself won’t do you any good at all, which is why we have things like --sudo and --ask-sudo-pass

Ansible will work fine with your remote sudo system and feed in the password when required when the remotes need it.

However, you must always supply it, as Ansible doesn’t want you saving your sudo password for those remote systems in the file. Note: this may not be the password used on the local system.

---

<div class="post-metadata">

**Author:** ![anatoly\_techtonik](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@anatoly\_techtonik](https://forum.ansible.com/u/anatoly_techtonik)\
**Post date:** [December 6, 2013, 3:10pm UTC](https://forum.ansible.com/t/ask-sudo-password-only-when-needed/14089/3 "2013-12-06T15:10:45Z")

</div>

> It's totally not pointless.
> 
> If you sudo ansible, you are running ansible as root locally.
> 
> It sounds like you aren't managing any remote systems in your case, so  
> you're in a minority use case.

Yes, I am running with local connection type to manage single node from within  
the node itself. Like I have different protocol for remote access and  
it is easier  
for me to just upload everything there and execute ansible-playbook from  
checkout.

> Ansible is designed around managing remote systems, where sudo'ing ansible  
> itself won't do you any good at all, which is why we have things like --sudo  
> and --ask-sudo-pass
> 
> Ansible will work fine with your remote sudo system and feed in the password  
> when required when the remotes need it.
> 
> However, you must always supply it, as Ansible doesn't want you saving your  
> sudo password for those remote systems in the file. Note: this may not be  
> the password used on the local system.

I see. Still, if it is possible to hack it somehow easily for local  
connection type.  
I may spend a time to make a patch.
