Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make chef execute with a specific user and load its environment values

Hi I am creating a WCS instance, for which i have to execute the create instance command using the wcs user (webadmin), its failing to connect to DB as its not able to get the required env variables.

so i put some sample code to check

I am using the below code

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 am getting the user

webadmin

But for env i am getting the env of the user "root", its not sourcing the .bash_profile for the env variables. Any ideas

like image 693
Saurav Avatar asked Jul 12 '13 11:07

Saurav


1 Answers

There is an environment attribute in the bash resource. Or you can source the .bash_profile in the script. That's one of the things you can do with bash (last example)

like image 151
Paulo Almeida Avatar answered Sep 22 '22 04:09

Paulo Almeida