不能让厨师在某个用户下运行bash

时间:2013-11-19 23:16:58

标签: bash chef

鉴于以下主厨食谱摘要:

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”

这对我来说是个问题,因为我需要所有的source和bash命令作为someUser运行。

1 个答案:

答案 0 :(得分:17)

我必须通过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

作为旁注,您是否创建了用户?

相关问题