【问题标题】:.profile not getting executed on chef client.profile 未在厨师客户端上执行
【发布时间】:2015-10-07 11:54:08
【问题描述】:

我的厨师服务器上有以下食谱:

# Insert the environment variables in .profile
execute "set-env-path" do
  command "echo 'export JAVA_HOME=/home/node/jdk1.6.0_45' >> /home/node/.profile && echo 'export PATH=$PATH:$JAVA_HOME/bin' >> /home/node/.profile"
end

# Execute .profile
execute "execute .profie" do
  command ". $HOME/.profile"
end 

当我在客户端上运行配方时,环境变量被插入到 .profile 中,但它们没有被设置。

node@node-virtual-machine:~$ sudo chef-client
[2014-04-07T14:59:57+05:30] INFO: Forking chef instance to converge...
Starting Chef Client, version 11.10.4
[2014-04-07T14:59:57+05:30] INFO: *** Chef 11.10.4 *** 
[2014-04-07T14:59:57+05:30] INFO: Chef-client pid: 24177
[2014-04-07T14:59:57+05:30] INFO: Run List is [recipe[remote_file]]
[2014-04-07T14:59:57+05:30] INFO: Run List expands to [remote_file]
[2014-04-07T14:59:57+05:30] INFO: Starting Chef Run for node-virtual-machine
[2014-04-07T14:59:57+05:30] INFO: Running start handlers
[2014-04-07T14:59:57+05:30] INFO: Start handlers complete.
[2014-04-07T14:59:58+05:30] INFO: HTTP Request Returned 404 Object Not Found: 
resolving cookbooks for run list: ["remote_file"]
[2014-04-07T14:59:58+05:30] INFO: Loading cookbooks [remote_file]
Synchronizing Cookbooks:
[2014-04-07T14:59:58+05:30] INFO: Storing updated cookbooks/remote_file/recipes/default.rb in the cache.
  - remote_file
    Compiling Cookbooks...
Converging 2 resources
Recipe: remote_file::default
  * execute[set-env-path] action run[2014-04-07T14:59:58+05:30] INFO: Processing execute[set-env-path] action run (remote_file::default line 39)
[2014-04-07T14:59:58+05:30] INFO: execute[set-env-path] ran successfully

- execute echo 'export JAVA_HOME=/home/node/jdk1.6.0_45' >> /home/node/.profile && echo 'export PATH=$PATH:$JAVA_HOME/bin' >> /home/node/.profile

* execute[set-env-path2] action run[2014-04-07T14:59:58+05:30] INFO: Processing execute[set-env-path2] action run (remote_file::default line 44)
[2014-04-07T14:59:58+05:30] INFO: execute[set-env-path2] ran successfully

- execute . $HOME/.profile

[2014-04-07T14:59:58+05:30] INFO: Chef Run complete in 0.511487679 seconds

Running handlers:
[2014-04-07T14:59:58+05:30] INFO: Running report handlers
Running handlers complete

[2014-04-07T14:59:58+05:30] INFO: Report handlers complete
Chef Client finished, 2/2 resources updated in 1.150640709 seconds
node@node-virtual-machine:~$ echo $JAVA_HOME

node@node-virtual-machine:

为什么 .profile 文件没有在 chef 客户端上执行,为什么我的环境变量没有通过 chef 设置?

【问题讨论】:

  • 有人知道上述解决方案吗?

标签: chef-infra chef-recipe chef-solo


【解决方案1】:

当 Chef 运行 execute 资源(包括 bashscript 等)时,它们在子 shell 中执行。您只是为该子 shell 设置环境,而不是 Chef Client 进程。如果需要设置环境变量,则需要使用 Ruby 块和 ENV 哈希:

ruby_block 'set environment' do
  block do
    ENV['MY_VARIABLE'] = 'MY_VALUE'
  end
end

【讨论】:

  • 我使用了你的代码,但是环境变量没有被永久设置。如何从厨师工作站将它们永久设置在我的厨师节点上
  • 您仍然需要写出 /etc/profile.d 或由 shell 加载的某种类型的文件
  • 如果我把它写在 /etc/profile.d 中而不是我需要重新启动机器以反映更改,我不想重新启动系统。有没有其他办法?
  • 这不是真的 - 你需要登录/注销或只是source /etc/profile
  • 在我输入命令源/etc/profile的recepie中,我收到一个找不到源的错误:(我相信recepie无法检测到源命令
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-05
  • 1970-01-01
相关资源
最近更新 更多