如何使厨师与特定用户一起执行并加载其环境值 [英] how to make chef execute with a specific user and load its environment values

查看:52
本文介绍了如何使厨师与特定用户一起执行并加载其环境值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在创建一个WCS实例,对于该实例,我必须使用wcs用户(webadmin)执行create instance命令,由于无法获取所需的env变量,因此无法连接到数据库。

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.

所以我放了一些示例代码进行检查

我正在使用以下代码

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

对于whoami我正在吸引用户

For whoami i am getting the user


webadmin

webadmin

但是对于env,我得到了用户 root的env,它没有为env变量提供.bash_profile。任何想法

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

推荐答案

environment 属性= https://docs.chef.io/resource_bash.html rel = nofollow noreferrer> bash 资源。或者,您可以在脚本中获取.bash_profile。这就是您可以使用bash进行的一项操作(最后一个示例)

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)

这篇关于如何使厨师与特定用户一起执行并加载其环境值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆