# Per-host sudo options

**URL:** <https://forum.ansible.com/t/per-host-sudo-options/12629>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [April 4, 2013, 9:48pm UTC](https://forum.ansible.com/t/per-host-sudo-options/12629 "2013-04-04T21:48:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [April 4, 2013, 9:48pm UTC](https://forum.ansible.com/t/per-host-sudo-options/12629/1 "2013-04-04T21:48:42Z")

</div>

Since you can set the ssh user to root, sudo becomes irrelevant (normally root can sudo, even if he doesn’t need to).

A diff use case though:  
some machines have sudo NOPASSWD, others don’t, ansible will hang on one or the other depending on -K being used or not.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 4, 2013, 10:08pm UTC](https://forum.ansible.com/t/per-host-sudo-options/12629/2 "2013-04-04T22:08:08Z")

</div>

A patch to enable

ansible\_sudo=True/False

in inventory would be accepted.

You should of course always use keys if you get into the scenario Brian mentioned, but it’s safe to do --ask-sudo-pass everywhere if some machines didn’t invoke the sudo code as you propose.

---

<div class="post-metadata">

**Author:** ![Steve\_Weber](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@Steve\_Weber](https://forum.ansible.com/u/Steve_Weber)\
**Post date:** [April 14, 2013, 1:17am UTC](https://forum.ansible.com/t/per-host-sudo-options/12629/3 "2013-04-14T01:17:47Z")

</div>

I have the same issue… here is something that works but likely not the best place to put it.  
I think the project maintainer should take a look at this since it would de a common issue /once/ ansible becomes popular.

in ansible/lib/ansible/runner/ **init**.py

change function////

def \_executor\_internal(self, host):  
‘’’ executes any module one or more times ‘’’

host\_variables = self.inventory.get\_variables(host)

#WITH:  
if host\_variables.get(‘ansible\_sudo’, None):  
self.sudo = host\_variables.get(‘ansible\_sudo’, None) == ‘yes’

this allows the host var ansible\_sudo to force sudo if its set as yes.  
Note: this dont support True and Yes and the other ways to eval to positive.

---

<div class="post-metadata">

**Author:** ![Steve\_Weber](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@Steve\_Weber](https://forum.ansible.com/u/Steve_Weber)\
**Post date:** [April 14, 2013, 1:19am UTC](https://forum.ansible.com/t/per-host-sudo-options/12629/4 "2013-04-14T01:19:58Z")

</div>

perhaps use,

if host\_variables.get(‘ansible\_sudo’, None):  
self.sudo = host\_variables.get(‘ansible\_sudo’, None) == ‘True’

note if the value is set and is anything but True it will assume that value is false.

---

<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:** [April 14, 2013, 1:24am UTC](https://forum.ansible.com/t/per-host-sudo-options/12629/5 "2013-04-14T01:24:17Z")

</div>

Steve,

Don’t particularly care for the popularity implication and I’m the one with the previous comment in this thread already 🙂
