Chef infra .配置文件未在chef客户端上执行

Chef infra .配置文件未在chef客户端上执行,chef-infra,chef-recipe,chef-solo,Chef Infra,Chef Recipe,Chef Solo,我的厨师服务器上有以下菜谱: # 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/.pro

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

# 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运行执行资源(包括bash、脚本等)时,它们在子shell中执行。您只是在为该子shell设置环境,而不是Chef客户端进程。如果需要设置环境变量,则需要使用Ruby块和ENV哈希:

ruby_块“设置环境”do 布洛克道 ENV['MY_VARIABLE']='MY_VALUE' 终止 终止
有人知道上面的解决方案吗?我使用了您的代码,但环境变量并没有得到永久设置。如何从chef Workstation在我的chef节点上永久设置它们您仍然需要写出/etc/profile.d或外壳加载的某种类型的文件如果我写在/etc/profile.d中,那么我需要重新启动计算机以反映更改,我不想重新启动系统。还有其他方法吗?那不是真的-你需要登录/注销,或者只是在recepie中输入/etc/profile在我输入的命令source/etc/profile中,我得到了一个找不到source的错误:我认为recepie无法检测到source命令