Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

up vote 9 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

 
discard

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.