When puppet exec's as a user, how can I get environment set for that user?
I've noticed that when I use the user
option on exec
, it doesn't take the environment of the specified user.
$ sudo -i puppet apply -e "exec { '/usr/bin/env': logoutput => true, user => nobody}"
notice: /Stage[main]//Exec[/usr/bin/env]/returns: SHELL=/bin/bash
notice: /Stage[main]//Exec[/usr/bin/env]/returns: USER=root
notice: /Stage[main]//Exec[/usr/bin/env]/returns: USERNAME=root
notice: /Stage[main]//Exec[/usr/bin/env]/returns: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
notice: /Stage[main]//Exec[/usr/bin/env]/returns: MAIL=/var/mail/root
notice: /Stage[main]//Exec[/usr/bin/env]/returns: PWD=/root
notice: /Stage[main]//Exec[/usr/bin/env]/returns: HOME=/root
notice: /Stage[main]//Exec[/usr/bin/env]/returns: LOGNAME=root
notice: /Stage[main]//Exec[/usr/bin/env]/returns: executed successfully
So while the command runs as nobody
, USER
, HOME
, etc. aren't set as expected. Is there any way I can get exec
to simulate a login shell so that the environment is setup as expected?
There's no way to get exec
to simulate a login shell. You can always use su -
(as suggested by womble) to get produce a login shell, but if all you want are environment variables controlled by Puppet, just use the parameter environment
.
Sure, run the command via su -
rather than specifying the user in the manifest.