相关疑难解决方法(0)

如何让厨师执行特定用户并加载其环境值

嗨我正在创建一个WCS实例,我必须使用wcs用户(webadmin)执行create instance命令,因为它无法获取所需的env变量而无法连接到DB.

所以我把一些示例代码检查

我使用以下代码

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
Run Code Online (Sandbox Code Playgroud)

对于whoami我得到了用户

WebAdmin的

但是对于env我得到了用户"root"的env,它没有为env变量获取.bash_profile.有任何想法吗

chef-infra chef-recipe

9
推荐指数
1
解决办法
6564
查看次数

标签 统计

chef-infra ×1

chef-recipe ×1