8

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?

2 Answers 2

11

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.

7

Sure, run the command via su - rather than specifying the user in the manifest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.