Chef infra 在chef中指定环境

Chef infra 在chef中指定环境,chef-infra,Chef Infra,我有一个java应用程序,其spring属性通过environment属性传递,如下所示 name "dev" description "The test environment" override_attributes({"dspring" => {"active_profile" => "dev", "jss_cert_location" => "/opt/mount1/certs/jss

我有一个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
如何在每个chef环境(开发、测试、阶段和产品)中定义“-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

假设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 %>
/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=
chef中的模板使用erb渲染最终文件

  • 是erb中的占位符
  • node.chef_environment
    是chef节点对象的一种方法,该对象提供节点的环境名称

您能否分享负责运行/设置ruby应用程序的配方代码?(顺便说一句,您提到了ruby应用程序,但在示例中,它似乎是python应用程序)