我有一个java应用程序,spring属性通过environment属性传递,如下所示。
name "dev"
description "The test environment"
override_attributes({"dspring" => {"active_profile" => "dev",
"jss_cert_location" => "/opt/mount1/certs/jssecacerts"},
我正在寻找类似的方法来为Chef中的ruby应用程序定义环境。用于执行此应用程序的命令是:
/usr/local/bin/python2.7 /opt/mount2/ozz/current/src/main.py --port=8080 --debug --log_file_prefix=/opt/mount2/ozz/logs/ozz.log --log_file_max_size=1000000 --env=test
如何在每个厨师环境(开发,测试,阶段和产品)中定义此“--env”参数?
以下是食谱摘录:
ark 'python' do
url 'https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz'
path "/opt/mount1/"
owner 'python'
action :put
end
execute "cd #{node[:base_dir]}/python && ./configure && make && make altinstall" do
not_if { File.exists?('/usr/local/bin/python2.7') }
end
remote_file "#{node[:base_dir]}/get-pip.py" do
source "https://bootstrap.pypa.io/get-pip.py"
mode 00755
not_if { File.exists?("#{node[:base_dir]}/get-pip.py")}
end
execute "/usr/local/bin/python2.7 #{node[:base_dir]}/get-pip.py"
cookbook_file "ua-parser-master.tar" do
path "/tmp/ua-parser-master.tar"
not_if { File.exists?('/tmp/ua-parser-master.tar') }
end
execute 'tar -C /tmp -xvf /tmp/ua-parser-master.tar && chown -R root.root /tmp/ua-parser-master/ && /usr/local/bin/pip install /tmp/ua-parser-master'
execute '/usr/local/bin/pip install tornado pyyaml user-agents'
template "/etc/init.d/#{node[:application_name]}" do
source 'python_init'
mode 00755
owner 'root'
group 'root'
variables(
:application_name => node[:application_name],
)
end
deploy_revision "/opt/mount1/#{node[:application_name]}" do
repo "#{node[:application_repo]}"
user "python"
keep_releases 10
action :deploy
migrate false
symlink_before_migrate.clear
create_dirs_before_symlink
purge_before_symlink.clear
symlinks.clear
symlinks {}
notifies :restart, "service[#{node[:application_name]}]"
end
service "#{node[:application_name]}" do
supports :restart => true
action :enable
end
答案 0 :(得分:0)
假设chef环境与您希望传递的参数匹配,并且该命令位于此模板中:
template "/etc/init.d/#{node[:application_name]}" do
source 'python_init'
mode 00755
owner 'root'
group 'root'
variables(
:application_name => node[:application_name],
)
end
执行的python_init
模板行可以写成:
/usr/local/bin/python2.7 /opt/mount2/ozz/current/src/main.py --port=8080 --debug --log_file_prefix=/opt/mount2/ozz/logs/ozz.log --log_file_max_size=1000000 --env=<%= node.chef_environment %>
chef中的模板使用erb来渲染最终文件。
<%= variable %>
是erb中的占位符node.chef_environment
是Chef节点对象的一个方法,它给出了节点的环境名称。