# How to set the path for sudo?

**URL:** <https://forum.ansible.com/t/how-to-set-the-path-for-sudo/13099>\
**Category:** Ansible Project\
**Created:** [July 11, 2013, 11:35am UTC](https://forum.ansible.com/t/how-to-set-the-path-for-sudo/13099 "2013-07-11T11:35:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Winkler](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Alexander\_Winkler](https://forum.ansible.com/u/Alexander_Winkler)\
**Post date:** [July 11, 2013, 11:35am UTC](https://forum.ansible.com/t/how-to-set-the-path-for-sudo/13099/1 "2013-07-11T11:35:33Z")

</div>

Hello,  
I am trying to use ansible 1.2 with Solaris 10 systems. Sudo is installed and configured on the target systems, but the binary is not in the path variable (it’s /usr/local/bin/sudo).  
Of course i could connect to every Solaris 10 server and edit the path…  
But (in my opinion) it’s better to reference the path within an ansible playbook. Is it possible to tell ansible, where it has to search for the sudo binary?

---

<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:** [July 11, 2013, 12:11pm UTC](https://forum.ansible.com/t/how-to-set-the-path-for-sudo/13099/2 "2013-07-11T12:11:38Z")

</div>

Currently the sudo executable called can be set in ansible.cfg, though this is there to support those that wish to use other sudo compatible implementations, and is global.

It is not possible to set this variable on a per inventory record basis, though it would be possible to tweak Ansible to allow this (pull requests would be welcome, if not, file a ticket).

Ultimately you _do_ need to edit the path right now.

I’m not sure if other folks on Solaris 10 have had this problem, that seems pretty unfortunate that the OS developers wouldn’t bother putting sudo in the user’s path.

---

<div class="post-metadata">

**Author:** ![Alexander\_Winkler](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Alexander\_Winkler](https://forum.ansible.com/u/Alexander_Winkler)\
**Post date:** [July 11, 2013, 2:40pm UTC](https://forum.ansible.com/t/how-to-set-the-path-for-sudo/13099/3 "2013-07-11T14:40:16Z")

</div>

Of course, changing the default profile would be the best solution. Luckily I can do this with ansible, by changing the sudo-path inside ansible.cfg temporary.

This should work. Thank you.

---

<div class="post-metadata">

**Author:** ![work](https://avatars.discourse-cdn.com/v4/letter/w/e99b99/32.png) [@work](https://forum.ansible.com/u/work)\
**Post date:** [September 12, 2013, 6:05am UTC](https://forum.ansible.com/t/how-to-set-the-path-for-sudo/13099/4 "2013-09-12T06:05:06Z")

</div>

Hi again,  
I recently catched that running an command directly with ssh won’t load the profile (e.g. ‘ssh host sudo command’, and that’s what ansible does). It seems like the environment variables are taken from /etc/default/login. In my case, sudo is placed in /usr/local/bin and that is not in the path by default.  
‘ssh host echo $PATH’ just showed up /usr/bin and /bin. So adding “PATH=/usr/bin:/bin/:/usr/local/bin” to /etc/default/login seems to be the way to make sudo working with direct ssh connect.

How did you manage this problem? I just feel like I am doing something the wrong way O\_o

---

<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:** [September 12, 2013, 5:44pm UTC](https://forum.ansible.com/t/how-to-set-the-path-for-sudo/13099/5 "2013-09-12T17:44:20Z")

</div>

You should not rely on remove environment variables for centralized configuration management – trusting the user environment is sane is not a good way to get a reliable configuration.

That being said, look into the environment parameter in Ansible if you wish to forceable push down environment settings like an HTTP\_PROXY value.

---

<div class="post-metadata">

**Author:** ![work](https://avatars.discourse-cdn.com/v4/letter/w/e99b99/32.png) [@work](https://forum.ansible.com/u/work)\
**Post date:** [September 13, 2013, 7:24am UTC](https://forum.ansible.com/t/how-to-set-the-path-for-sudo/13099/6 "2013-09-13T07:24:45Z")

</div>

Addind the environment to every task wouldn’t be a better solution in my optionen.

How are other users manage sudo not beeing in the standard path?

---

<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:** [September 13, 2013, 1:28pm UTC](https://forum.ansible.com/t/how-to-set-the-path-for-sudo/13099/7 "2013-09-13T13:28:26Z")

</div>

My apologies.

I didn’t suggest that for setting the path to sudo, but rather for cases where sudo was eating your environment.

You can control the path to sudo in ansible.cfg

---

<div class="post-metadata">

**Author:** ![work](https://avatars.discourse-cdn.com/v4/letter/w/e99b99/32.png) [@work](https://forum.ansible.com/u/work)\
**Post date:** [September 13, 2013, 1:44pm UTC](https://forum.ansible.com/t/how-to-set-the-path-for-sudo/13099/8 "2013-09-13T13:44:41Z")

</div>

Configuring the path for sudo in ansible.cfg is a suitable way for an homogenous inventory. But not if you have various operating systems with sudo in different paths and you want to manage everything with one call of an enormous playbook.

---

<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:** [September 13, 2013, 1:49pm UTC](https://forum.ansible.com/t/how-to-set-the-path-for-sudo/13099/9 "2013-09-13T13:49:00Z")

</div>

Yes, I agree that’s suboptimal in the case where they are different.

I’m open to patches that would allow it to be configured as an inventory variable also.

We occasionally do that for parameters we add first and then decide they should be specific host tunable. (See discussion also about per group host key checking configuration).

If this is not something you’d like to (or feel comfortable) working on, can you open a feature request in github so we don’t forget?

Thanks!

–Michael
