Given the following chef cookbook snippet:
bash "source a file" do
user "someUser"
cwd "/tmp"
code <<-EOH
source /tmp/test.sh
EOH
end
where /tmp/test.sh contains:
echo $USER >> /tmp/out.log
/tmp/out.log then contains "root" not "someUser"
This is causing issues for me since I need all source and bash commands to run as someUser.
Something I had to learn the hard way with Chef: It may actually be running as the user, but the environment variables aren't set.
To see this for yourself, run
echo `whoami`
If you need the environment variables set, just set them (or source a .bash_profile
):
bash "source a file" do
user "someUser"
cwd "/tmp"
environment ({'HOME' => '/home/someUser', 'USER' => 'someUser'})
code <<-EOH
source /tmp/test.sh
EOH
end
As a side note, have you created the user?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With