Can't get a chef to run bash under a specific user

Given the following snippet of the chef's cookbook:

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 causes problems for me, since I need all the source and bash commands to run as someUser.

+6
source share
1 answer

I had to study something with the chef diligently: he can work as a user, but environment variables are not set .

To verify this, run

 echo `whoami` 

If you need environment variables, just set them (or type 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 you noticed, have you created a user?

+17
source

Source: https://habr.com/ru/post/958429/


All Articles