How to get a chef to execute with a specific user and load his environment values

Hi, I am creating a WCS instance for which I have to run the create instance command using wcs user (webadmin), and could not connect to the DB because it could not get the required env variables.

, so I put the sample code to check

I am using the code below

bash "wcs-create-instance" do user "webadmin" group "webspher" code <<-EOH ###{node[:websphere][:wcs][:wcs_installLocation]}/bin/config_ant.sh -DinstanceName=#{node[:websphere][:wcs][:wcs_instance]} CreateInstance whoami > /tmp/whoami env > /tmp/env EOH notifies :run, "bash[fix-permission]", :immediately #This not_if is just temporary, a proper mechanism has to be implemented here to loop through all the WCS APars, #For the POC keeping it neat and simple such that this does not rerun on execution not_if {File.directory?("#{node[:websphere][:wcs][:wcs_installLocation]}/instances/#{node[:websphere][:wcs][:wcs_instance]}/starterstores")} #action :nothing end 

For whoami, I get a user

Webadmin

But for env, I get the user env "root" without using the SQL .bash_profile file for env variables. Any ideas

+9
chef chef-recipe
source share
2 answers

There is an environment attribute in the bash resource . Or you can specify .bash_profile in a script. This is one of the things you can do with bash (last example)

+7
source share

It seems that adding flags '-l' to tell bash that it should act as an input shell also helps.

 bash 'do something' do code 'my_command' flags '-l' end 

Or using the execute block:

 execute 'foo' do command 'bash -l -c "my_command"' end 
0
source share

All Articles