如何使用厨师食谱设置环境变量? [英] How can you use a Chef recipe to set an environment variable?

查看:199
本文介绍了如何使用厨师食谱设置环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用厨师配方设置环境变量?

How can you use a Chef recipe to set an environment variable?

我需要使用厨师配方设置一个环境变量。你可以提供一个如何实现这个的例子吗?

I need to set an environment variable using a Chef recipe. Can you provide an example of how to accomplish this?

推荐答案

如果你需要严格的厨师进程中的env var set,可以使用 ENV ['foo'] ='bar ',因为它是一个红宝石进程。

If you need an env var set strictly within the Chef process, you can use ENV['foo'] = 'bar' since it's a ruby process.

如果你需要为执行提供者设置一个,Chef发布环境哈希:

If you need to set one for an execute provider, Chef exposes an environment hash:

execute 'Bootstrap the database' do 
  cwd "#{app_dir}/current"
  command "#{env_cmd} rake db:drop db:create db:schema:load RAILS_ENV=#{rails_env}"
  environment 'HOME' => "/home/#{app_user}"
  user app_user
  action :run
  not_if %[psql -U postgres -c "\\l" | grep #{db_name}]
end

如果您要设置持久环境变量,那么你可能想要厨师编辑 /etc/profile.d/chef.sh / etc / environment ,用户个人资料等。

If you're looking to set a persistent environment variable then you may want to have Chef edit /etc/profile.d/chef.sh, /etc/environment, a users' profile, etc.

这篇关于如何使用厨师食谱设置环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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