【问题标题】:cant get chef to run bash under a certain user无法让厨师在某个用户下运行 bash
【发布时间】:2024-01-03 13:18:01
【问题描述】:

鉴于以下厨师食谱 sn-p:

bash "source a file" do
  user "someUser"
  cwd "/tmp"
  code <<-EOH
source /tmp/test.sh
  EOH
end

/tmp/test.sh 包含:

echo $USER >> /tmp/out.log

/tmp/out.log 然后包含“root”而不是“someUser”

这给我带来了问题,因为我需要以 someUser 身份运行所有源代码和 bash 命令。

【问题讨论】:

    标签: bash chef-infra


    【解决方案1】:

    我必须通过 Chef 艰难地学习一些东西:它实际上可能以用户身份运行,但环境变量未设置

    要亲自查看,请运行

    echo `whoami`
    

    如果您需要设置环境变量,只需设置它们(或来源.bash_profile):

    bash "source a file" do
      user "someUser"
      cwd "/tmp"
      environment ({'HOME' => '/home/someUser', 'USER' => 'someUser'})
      code <<-EOH
    source /tmp/test.sh
      EOH
    end
    

    附带说明一下,您是否创建了用户?

    【讨论】:

    最近更新 更多