用`magic_shell`菜谱更新$ PATH [英] Updating $PATH with `magic_shell` Cookbook

查看:73
本文介绍了用`magic_shell`菜谱更新$ PATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了2本食谱:java_kevin和maven_kevin:

I created 2 cookbooks: java_kevin and maven_kevin:

cookbooks / java_kevin / recipes / default.rb >

node.default['user'] = 'vagrant' 
node.default['user_home'] = '/home/' + node['user'] 
node.default['my_dir'] = node['user_home'] + '/my'

node.default['vagrant'] = '/vagrant'

node.default['java_home'] = node['my_dir'] + '/jdk1.7.0_51'

# Install Java 7 RPM
execute "install_oracle_java7" do
    command "rpm -ivh --prefix=" + node['my_dir'] + " jdk-7u51-linux-x64.rpm"
    cwd node['vagrant']
    creates node['java_home']
end

magic_shell_environment 'JAVA_HOME' do 
    value node['java_home']
end 

magic_shell_environment 'PATH' do 
    value "$PATH:" + node['java_home'] + '/bin'
end 

菜谱/maven_kmm/recipes/default.rb

node.default['user'] = 'vagrant' 
node.default['user_home'] = '/home/' + node['user'] 
node.default['my_dir'] = node['user_home'] + '/my'

node.default['maven_download_dir'] = node.default['user_home'] + '/apache-maven-3.2.1-bin.tar.gz'

# Download Maven 3.2.1
remote_file node['maven_download_dir'] do
    source "http://www.bizdirusa.com/mirrors/apache/maven/maven-3/3.2.1/binaries/apache-maven-3.2.1-bin.tar.gz"
    checksum "aaef971206104e04e21a3b580d9634fe"
end

execute "unpack_and_uncompress_maven" do
    command "tar -zxvf " + node['maven_download_dir']
    cwd node['user_home']
    creates node['user_home'] + '/apache-maven-3.2.1'
end

execute "move_maven_to_my_dir" do
    command "mv " + node['user_home'] + '/apache-maven-3.2.1' + " " + node['my_dir']
    cwd node['user_home']
    creates node['my_dir'] + '/apache-maven-3.2.1'
end

node.default['maven_home'] = node['my_dir'] + '/apache-maven-3.2.1'

magic_shell_environment 'M2_HOME' do 
    value node['maven_home']
end 

magic_shell_environment 'PATH' do 
    value "$PATH:" + node['maven_home'] + '/bin'
end 

配置后,我只会看到Maven路径已正确添加到 $ PATH

After provisioning, I only see that the Maven path was properly added to the $PATH:

[vagrant@vagrant-centos65 ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/my/apache-maven-3.2.1/bin:/home/vagrant/bin

[vagrant@vagrant-centos65 ~]$ which mvn
~/rm/apache-maven-3.2.1/bin/mvn

[vagrant@vagrant-centos65 ~]$ which java
/usr/bin/which: no java in (/usr/local/bin:/bin:/usr/bin:....

为什么是 JAVA_HOME 不是最终 $ PATH 项的一部分吗?

Why was JAVA_HOME not part of the final $PATH item?

解决方案

我相信magic_shell_environment会为每个资源名称(此处为'PATH'-检查/etc/profile.d/PATH.sh)创建一个唯一的文件,并且每次创建该文件将被重新创建。在这里,您的两个配方都试图创建相同的文件。并且最有可能是第一个配方创建的PATH.sh文件被第二个配方覆盖。

I believe that magic_shell_environment creates a unique file for each resource name (here, 'PATH' -- Check /etc/profile.d/PATH.sh) and that each time the file will be recreated. Here both of your recipes are attempting to create the same file. And most likely the PATH.sh file created by the first recipe is getting overwritten by the second recipe.

我不确定如何使用magic_shell修复此问题,但是我相信这就是您的问题为什么的答案。

I'm not sure how to fix this using magic_shell, but I believe that is the answer to your question "why" .

请参见 https://github.com/customink-webops/magic_shell/blob/master/providers/environment.rb

这篇关于用`magic_shell`菜谱更新$ PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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