Permalink
Browse files

コマンドライン引数 -S hosts= で特定のホストのみ対象に実行する

  • Loading branch information...
1 parent a51c92e commit 7d0a27e8f902fe2b28908e60b30db7e73c13e530 @fujiwara committed Jul 5, 2012
Showing with 23 additions and 9 deletions.
  1. +2 −0 .gitignore
  2. +19 −7 config/deploy.rb
  3. +2 −2 json/base.json
View
@@ -1 +1,3 @@
*~
+config/solo.rb
+config/self.json
View
@@ -1,13 +1,25 @@
+require "json"
+
set :application, "chef-solo"
set :chef_dir, "/root/chef"
set :hostname, `hostname -s`.chomp
-
-require "json"
-JSON.parse( open("#{chef_dir}/json/base.json").read )["hosts"].keys.each do |host|
- role :host, host
+set :json_dir, "#{chef_dir}/json"
+set :config_dir, "#{chef_dir}/config"
+set :bin_dir, "#{chef_dir}/bin"
+set :base, JSON.parse( File::open("#{json_dir}/base.json").read )
+
+if exists? :hosts
+ hosts.split(",").each do |host|
+ role :host, host
+ end
+else
+ base["hosts"].keys.sort.each do |host|
+ role :host, host
+ end
end
namespace :chef do
+
task :default do
init_config
sync
@@ -16,20 +28,20 @@
end
task :init_config do
- File::open("#{chef_dir}/config/solo.rb", "w") {|f|
+ File::open("#{config_dir}/solo.rb", "w") {|f|
f.puts "file_cache_path '/tmp/chef-solo'"
f.puts "cookbook_path '#{chef_dir}/cookbooks'"
f.puts "node_name `hostname -s`.chomp"
}
end
task :merge_json, :roles => :host do
- run "cd #{chef_dir} && export HOST=`hostname -s`; ./bin/merge_json json/base.json json/${HOST}.json > config/self.json"
+ run "export HOST=`hostname -s`; #{bin_dir}/merge_json #{json_dir}/base.json #{json_dir}/${HOST}.json > #{config_dir}/self.json"
end
desc "run chef-solo"
task :run_chef, :roles => :host do
- run "chef-solo -c #{chef_dir}/config/solo.rb -j #{chef_dir}/config/self.json"
+ run "chef-solo -c #{config_dir}/solo.rb -j #{config_dir}/self.json"
end
desc "rsync #{chef_dir}"
View
@@ -1,7 +1,7 @@
{
"hosts": {
- "web01": "192.168.0.101",
- "app01": "192.168.0.102"
+ "sl6": "192.168.1.201",
+ "centos5": "192.168.1.202"
},
"nameservers": ["192.168.0.1", "8.8.8.8", "8.8.4.4"],
"run_list": [

0 comments on commit 7d0a27e

Please sign in to comment.