12. Sharing recipe on servers and local
Production/QA
Local
Knife-Solo
Vagrant
roles/api.rb
Vagrantfile
run_list(
config.vm.provision :chef_solo do |chef|
chef.add_recipe "base::git"
"role[base]",
chef.add_recipe "nginx"
"recipe[nginx]",
"recipe[python]",
chef.add_recipe "php_pack"
"recipe[repos::api]",
chef.add_recipe "python"
"recipe[monit]",
chef.add_recipe "repos::api"
:
"recipe[monit::nginx]",
:
"recipe[monit::api]"
:
)
:
end
13. Changing server configuration in a template
cookbooks/repos/templates/api.erb
-----<%- case node[‘environment'] %>
<%- when "live" %>
Define in nodes/xxx.json
api_url = 'http://api.gengo.com'
<%- when "qa" %>
api_url = 'http://yyy.api.gengo.com'
<%- when "dev" %>
api_url = 'http://localhost:8080'
<%- end %>
------
or
Vagrantfile
14. Changing Resource in a Recipe.
cookbooks/repos/recipes/api/default.rb
if node['environment'] == "dev"
git "#{node['repos']['home']}/#{project}" do
repository "git@github.com:gengo/api.git"
ssh_wrapper "/tmp/private_code/wrap-ssh4git.sh"
action :checkout
notifies :restart, "service[#{project}]"
end
else
deploy "/mnt#{node['repos']['home']}/#{project}" do
ssh_wrapper "/tmp/private_code/wrap-ssh4git.sh"
repo 'git@github.com:gengo/api'
branch "#{node['repos']['branch']}"
keep_releases 3
notifies :restart, "service[#{project}]"
end
end