Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 10 down vote accepted

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.

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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