Chef infra 如何让chef与特定用户一起执行并加载其环境值

Chef infra 如何让chef与特定用户一起执行并加载其环境值,chef-infra,chef-recipe,Chef Infra,Chef Recipe,您好,我正在创建一个WCS实例,我必须使用WCS用户(webadmin)为其执行create instance命令,它无法连接到DB,因为它无法获取所需的环境变量 所以我放了一些示例代码来检查 我正在使用下面的代码 bash "wcs-create-instance" do user "webadmin" group "webspher" code <<-EOH ###{node[:websphere][:wcs][:wcs_i

您好,我正在创建一个WCS实例,我必须使用WCS用户(webadmin)为其执行create instance命令,它无法连接到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
bash“wcs创建实例”do
用户“webadmin”
组“webspher”
代码/tmp/env
EOH
通知:立即运行“bash[fix permission]”
#如果这只是暂时的,则必须在此处实施适当的机制,以循环所有WCS APAR,
#对于POC来说,保持其整洁和简单,这样就不会在执行时重新运行
如果{File.directory?(“{node[:websphere][:wcs][:wcs\u installLocation]}/instances/{node[:websphere][:wcs][:wcs\u instance]}/starterstores”)}
#行动:没什么
结束
对于whoami,我得到了用户

网站管理员


但是对于env,我得到的是用户“root”的env,而不是env变量的.bash_配置文件。任何想法

中都有一个
环境
属性。也可以在脚本中找到.bash_配置文件的源代码。这是(最后一个示例)

似乎添加了
标志'-l'
,以告诉bash充当登录shell也起到了作用

bash 'do something' do
  code 'my_command'
  flags '-l'
end
或者使用
execute
块:

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

尝试源代码,但它不起作用,因为有很多环境变量要设置,在bash资源中运行命令时设置它将非常麻烦。似乎我做错了什么,Paulo建议的解决方案是正确的,我确实生成了.bash_配置文件(这次正确),并且工作正常。谢谢again@Saurav你说你的资料来源正确。你能告诉我怎么做吗?甚至我也面临着采购bash的问题_profile@VinayKadalagi遵循保罗建议的链接。bash'foo'do code'source/tmp/foo.sh'endOr您可以使用环境属性执行“wcs创建实例”do user node['was']['usr']group node['was']['usr_grp']cwd'.{node['wcs']['wcs_installLocation']}/bin”环境('ORACLE_HOME'=>'.{node['ora u client']]HOME]}/product/{node['ora client']“,”TNS_ADMIN'=>node[“ora_client”][“TNS_home”])command./config_ant.sh-DinstanceName={node['wcs']['wcs_instance']}CreateInstance“not_如果{File.exists?”(“{node['wcs']['wcs_installLocation']}/instances/#{node['wcs']['wcs']]wcs']['u installLocation']]}实例]}/web/index.html}end}