Set PATH for Salt

2,254 views
Skip to first unread message

Travis Beauvais

unread,
Aug 16, 2013, 3:05:28 PM8/16/13
to salt-...@googlegroups.com
My salt minion is running under root. If I do echo $PATH as root user on the minion I get:

/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/opt/aws/bin:/ops/bin

If I get the path from salt, I get:

salt '*' cmd.run 'echo $PATH'
machine-01:
    /sbin:/usr/sbin:/bin:/usr/bin


How do I make sure salt is using the same path as normal users?

Travis Beauvais

unread,
Aug 16, 2013, 4:55:52 PM8/16/13
to salt-...@googlegroups.com
Also, if I do salt-call I get the right path.

salt-call cmd.run 'echo $PATH'
local:
    /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/opt/aws/bin:/ops/bin



Travis Beauvais

unread,
Aug 19, 2013, 1:02:02 PM8/19/13
to salt-...@googlegroups.com
Anyone?

David Boucha

unread,
Aug 19, 2013, 1:26:43 PM8/19/13
to salt users list
Sorry no one responded, Travis. I think this might be worth opening an issue on github.   github.com/saltstack/salt/issues/new


Thanks!


--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Dave Boucha  |  Sr. Engineer


5272 South College Drive, Suite 301 | Murray, UT 84123

office 801-305-3563
da...@saltstack.com | www.saltstack.com

Travis Beauvais

unread,
Aug 19, 2013, 1:26:47 PM8/19/13
to salt-...@googlegroups.com
By the way, I am on CentOS. I see in the Debian init file the path is explicitly set to "/sbin:/usr/sbin:/bin:/usr/bin" but I don't see that in any RHEL related files.

David Anderson

unread,
Aug 19, 2013, 1:32:46 PM8/19/13
to salt-...@googlegroups.com
When you run salt-call, it inherits the path environment from your
shell. When you go through salt via the salt minion process, you are
seeing the path environment as set when the service was started via
upstart/initscript/etc. Try setting your PATH in your salt-minion
upstart/init script or specify your path in the env dict for cmd.run.
http://docs.saltstack.com/ref/modules/all/salt.modules.cmdmod.html

root@salt-master:/# salt 'apt*' cmd.run 'echo $PATH'
apt.dubkat.com:
/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
root@apt / # salt-call cmd.run 'echo $PATH'
local:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin


root@apt / # PATH=/blah:$PATH
root@apt / # salt-call cmd.run 'echo $PATH'
local:
/blah:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
root@salt-master:/# salt 'apt*' cmd.run 'echo $PATH'
apt.dubkat.com:
/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin


Edit salt-minion upstart script to modify path:
env
PATH=myupstartpath:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
and restart salt-minion.

root@salt-master:/# salt 'apt*' cmd.run 'echo $PATH'
apt.dubkat.com:
myupstartpath:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
--
Dave

Travis Beauvais

unread,
Aug 19, 2013, 1:32:55 PM8/19/13
to salt-...@googlegroups.com
Thanks David. I submitted an issue. https://github.com/saltstack/salt/issues/6785

Rajat Batra

unread,
Dec 17, 2013, 9:03:36 PM12/17/13
to salt-...@googlegroups.com
This is actually really terrible that salt creates it's own environment and there is no way to give environment variables from the master for the minions. Having to edit the minion file is a horrible design/workaround. 

Does anyone have any updates on this:? Can you use pillars to define environment variables? 

The reason I ask is I require an http_proxy set for minions to get out of our firewall and am seeing similar behavior to David's issue with PATH. 

Any ideas would be awesome, 

Thanks, Raj

Clint Dilks

unread,
Dec 17, 2013, 9:16:18 PM12/17/13
to salt-...@googlegroups.com
Hi





The reason I ask is I require an http_proxy set for minions to get out of our firewall and am seeing similar behavior to David's issue with PATH. 



Most tools allow you to set proxy information in ways other than using environment variables.

For example yum on our CentOS systems has a proxy configured in yum.conf.

If we need wget to use the proxy we either puch out the proxy information to /etc/wgetrc or a .wgetrc file.


David Anderson

unread,
Dec 17, 2013, 10:39:14 PM12/17/13
to salt-...@googlegroups.com
Hi Rajat,

As Clint points out, there are usually better ways to specify things like http_proxy, however if you want salt-minion to have this environment variable set, you can either set 'http_proxy=...' in /etc/default/salt-minion (upstart systems) or /etc/default/salt (sysv init) systems.

My last comment on issue https://github.com/saltstack/salt/issues/6785 explains why this happens.

My pull request on Sep 11 fixes the ordering of sourced functions within the init scripts and adds functionality for upstart scripts:
--
Dave

Rajat Batra

unread,
Dec 20, 2013, 2:10:43 PM12/20/13
to salt-...@googlegroups.com
Thanks for the feedback guys, 

It seems I had to edit the python file, when installing salt through apt-get it creates a salt-minion that is a python script in /usr/bin 

I was then able to get past my proxy issue. 

Thanks for the pointers! 
Reply all
Reply to author
Forward
0 new messages