capstrap 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ # 0.3.0
2
+
3
+ * Add --config flag and read config from ~/.capstraprc by default.
4
+ * Refactor method_option blocks on tasks (dry it up).
5
+
1
6
  # 0.2.2
2
7
 
3
8
  * Add task method options for overriding git init/update behavior
@@ -39,6 +39,13 @@ To override the default cookbooks and configuration paths:
39
39
  --config-repo=git://github.com/fnichol/chef-dna-spike.git \
40
40
  --config-path=/opt/chef/config
41
41
 
42
+ To use a <code>rake update</code> instead of the default
43
+ <code>git submodule init && git submodule update</code> after a git update:
44
+
45
+ capstrap execute root@zland \
46
+ --cookbooks-rake-update \
47
+ --config-rake-update
48
+
42
49
  To execute a chef configuration (the full monty):
43
50
 
44
51
  capstrap execute root@zland \
@@ -58,6 +65,16 @@ To pull new cookbook/configuration updates and run chef-solo:
58
65
 
59
66
  capstrap update root@zland
60
67
 
68
+ To save config options to a yaml file to be read by capstrap:
69
+
70
+ cat > "$HOME/.capstraprc" <<END_OF_CAPSTRAPRC
71
+ ---
72
+ cookbooks-repo: git://github.com/fnichol/chef-repo.git
73
+ cookbooks-rake-update: true
74
+ config-repo: git://github.com/fnichol/chef-dna-spike.git
75
+ config-rake-update: true
76
+ END_OF_CAPSTRAPRC
77
+
61
78
  To get more help:
62
79
 
63
80
  capstrap help
@@ -1,4 +1,5 @@
1
1
  require 'thor'
2
+ require 'yaml'
2
3
  require 'capistrano'
3
4
  require 'capistrano/cli'
4
5
 
@@ -13,159 +13,124 @@ module Capstrap
13
13
  end
14
14
 
15
15
  desc "ruby HOST", "Install an RVM ruby on remote SSH host HOST"
16
- method_option "ruby", :type => :string, :desc =>
17
- "Version of ruby to install.", :default => "ree-1.8.7"
18
16
  method_option "default", :type => :boolean, :desc =>
19
17
  "Set this ruby to be RVM default."
20
18
  def ruby(ssh_host)
21
19
  @ssh_host = ssh_host
22
- abort ">> HOST must be set" unless @ssh_host
23
-
24
20
  setup_config options
25
-
26
- config.find_and_execute_task "rvm:install:#{options[:ruby]}"
27
- if options[:default]
28
- config.find_and_execute_task "rvm:default:#{options[:ruby]}"
29
- end
21
+ exec_ruby
30
22
  end
31
23
 
32
24
  desc "chef HOST", "Install chef gem on remote SSH host HOST"
33
- method_option "ruby", :type => :string, :desc =>
34
- "Version of ruby to install.", :default => "ree-1.8.7"
35
25
  def chef(ssh_host)
36
26
  @ssh_host = ssh_host
37
- abort ">> HOST must be set" unless @ssh_host
38
-
39
27
  setup_config options
40
-
41
- invoke :ruby, [ssh_host], :ruby => options[:ruby], :default => true
42
- config.find_and_execute_task "chef:install:lib"
28
+ exec_chef
43
29
  end
44
30
 
45
31
  desc "solo HOST", "Install chef cookbooks & config on remote SSH host HOST"
46
- method_option "ruby", :type => :string,
47
- :desc => "Version of ruby to install.",
48
- :default => "ree-1.8.7",
49
- :aliases => "-r"
50
- method_option "cookbooks-repo", :type => :string,
51
- :desc => "Chef cookbooks git repository URL.",
52
- :aliases => "-c"
53
- method_option "cookbooks-path", :type => :string,
54
- :desc => "Install path to chef cookbooks git repository.",
55
- :default => "/var/chef-solo",
56
- :aliases => "-p"
57
- method_option "cookbooks-rake-update", :type => :boolean, :desc =>
58
- "Run rake update vs. git submodule init/update when updating cookbooks repo",
59
- :default => false,
60
- :aliases => "-u"
61
- method_option "config-repo", :type => :string,
62
- :desc => "Chef configuration git repository URL.",
63
- :aliases => "-C"
64
- method_option "config-path", :type => :string,
65
- :desc => "Install path to chef configuration git repository.",
66
- :default => "/etc/chef",
67
- :aliases => "-P"
68
- method_option "config-rake-update", :type => :boolean, :desc =>
69
- "Run rake update vs. git submodule init/update when updating config repo",
70
- :default => false,
71
- :aliases => "-U"
72
32
  def solo(ssh_host)
73
33
  @ssh_host = ssh_host
74
- abort ">> HOST must be set" unless @ssh_host
75
-
76
34
  setup_config options
77
-
78
- unless options["cookbooks-repo"]
79
- abort ">> --cookbooks-repo=<git_url> must be set"
80
- end
81
- unless options["config-repo"]
82
- abort ">> --config-repo=<git_url> must be set"
83
- end
84
-
85
- invoke :chef, [ssh_host], :ruby => options[:ruby], :default => true
86
- config.find_and_execute_task "chef:install:cookbooks"
87
- config.find_and_execute_task "chef:install:config"
35
+ assert_repos_set
36
+ exec_solo
88
37
  end
89
38
 
90
39
  desc "execute HOST", "Executes chef solo config on remote SSH host HOST"
91
- method_option "ruby", :type => :string,
92
- :desc => "Version of ruby to install.",
93
- :default => "ree-1.8.7",
94
- :aliases => "-r"
95
- method_option "cookbooks-repo", :type => :string,
96
- :desc => "Chef cookbooks git repository URL.",
97
- :aliases => "-c"
98
- method_option "cookbooks-path", :type => :string,
99
- :desc => "Install path to chef cookbooks git repository.",
100
- :default => "/var/chef-solo",
101
- :aliases => "-p"
102
- method_option "cookbooks-rake-update", :type => :boolean, :desc =>
103
- "Run rake update vs. git submodule init/update when updating cookbooks repo",
104
- :default => false,
105
- :aliases => "-u"
106
- method_option "config-repo", :type => :string,
107
- :desc => "Chef configuration git repository URL.",
108
- :aliases => "-C"
109
- method_option "config-path", :type => :string,
110
- :desc => "Install path to chef configuration git repository.",
111
- :default => "/etc/chef",
112
- :aliases => "-P"
113
- method_option "config-rake-update", :type => :boolean, :desc =>
114
- "Run rake update vs. git submodule init/update when updating config repo",
115
- :default => false,
116
- :aliases => "-U"
117
40
  def execute(ssh_host)
118
41
  @ssh_host = ssh_host
119
- abort ">> HOST must be set" unless @ssh_host
42
+ setup_config options
43
+ assert_repos_set
44
+ exec_execute
45
+ end
120
46
 
47
+ desc "update HOST", "Updates and executes chef solo on remote SSH host HOST"
48
+ def update(ssh_host)
49
+ @ssh_host = ssh_host
121
50
  setup_config options
51
+ exec_update
52
+ end
53
+
54
+ [:ruby, :chef, :solo, :execute, :update].each do |task|
55
+ method_option "config", :for => task, :type => :string,
56
+ :desc => "Read from alternative configuration.",
57
+ :default => File.join(ENV['HOME'], ".capstraprc"),
58
+ :aliases => "-f"
122
59
 
123
- unless options["cookbooks-repo"]
60
+ method_option "ruby", :for => task, :type => :string,
61
+ :desc => "Version of ruby to install.",
62
+ :default => "ree-1.8.7"
63
+ end
64
+
65
+ [:chef, :solo, :execute, :update].each do |task|
66
+ method_option "cookbooks-path", :for => task, :type => :string,
67
+ :desc => "Install path to chef cookbooks git repository.",
68
+ :default => "/var/chef-solo",
69
+ :aliases => "-p"
70
+
71
+ method_option "cookbooks-rake-update", :for => task, :type => :boolean,
72
+ :desc => "Run rake update vs. git submodule init/update when updating cookbooks repo",
73
+ :default => false,
74
+ :aliases => "-u"
75
+
76
+ method_option "config-path", :for => task, :type => :string,
77
+ :desc => "Install path to chef configuration git repository.",
78
+ :default => "/etc/chef",
79
+ :aliases => "-P"
80
+
81
+ method_option "config-rake-update", :for => task, :type => :boolean,
82
+ :desc => "Run rake update vs. git submodule init/update when updating config repo",
83
+ :default => false,
84
+ :aliases => "-U"
85
+ end
86
+
87
+ [:chef, :solo, :execute].each do |task|
88
+ method_option "cookbooks-repo", :for => task, :type => :string,
89
+ :desc => "Chef cookbooks git repository URL.",
90
+ :aliases => "-c"
91
+
92
+ method_option "config-repo", :for => task, :type => :string,
93
+ :desc => "Chef configuration git repository URL.",
94
+ :aliases => "-C"
95
+ end
96
+
97
+ private
98
+
99
+ def assert_repos_set
100
+ unless config.fetch(:cookbooks_repo)
124
101
  abort ">> --cookbooks-repo=<git_url> must be set"
125
102
  end
126
- unless options["config-repo"]
103
+ unless config.fetch(:config_repo)
127
104
  abort ">> --config-repo=<git_url> must be set"
128
105
  end
106
+ end
129
107
 
130
- invoke :solo, [ssh_host], :ruby => options[:ruby], :default => true,
131
- :"cookbooks-repo" => options["cookbooks-repo"],
132
- :"cookbooks-path" => options["cookbooks-path"],
133
- :"config-repo" => options["config-repo"],
134
- :"config-path" => options["config-path"]
135
- config.find_and_execute_task "chef:execute:solo"
108
+ def exec_ruby
109
+ config.find_and_execute_task "rvm:install:#{config.fetch(:ruby)}"
110
+ if options[:default]
111
+ config.find_and_execute_task "rvm:default:#{config.fetch(:ruby)}"
112
+ end
136
113
  end
137
114
 
138
- desc "update HOST", "Updates and executes chef solo on remote SSH host HOST"
139
- method_option "ruby", :type => :string,
140
- :desc => "Version of ruby to install.",
141
- :default => "ree-1.8.7",
142
- :aliases => "-r"
143
- method_option "cookbooks-path", :type => :string,
144
- :desc => "Install path to chef cookbooks git repository.",
145
- :default => "/var/chef-solo",
146
- :aliases => "-p"
147
- method_option "cookbooks-rake-update", :type => :boolean, :desc =>
148
- "Run rake update vs. git submodule init/update when updating cookbooks repo",
149
- :default => false,
150
- :aliases => "-u"
151
- method_option "config-path", :type => :string,
152
- :desc => "Install path to chef configuration git repository.",
153
- :default => "/etc/chef",
154
- :aliases => "-P"
155
- method_option "config-rake-update", :type => :boolean, :desc =>
156
- "Run rake update vs. git submodule init/update when updating config repo",
157
- :default => false,
158
- :aliases => "-U"
159
- def update(ssh_host)
160
- @ssh_host = ssh_host
161
- abort ">> HOST must be set" unless @ssh_host
115
+ def exec_chef
116
+ exec_ruby
117
+ config.find_and_execute_task "chef:install:lib"
118
+ end
162
119
 
163
- setup_config options
120
+ def exec_solo
121
+ exec_chef
122
+ config.find_and_execute_task "chef:install:cookbooks"
123
+ config.find_and_execute_task "chef:install:config"
124
+ end
164
125
 
165
- config.find_and_execute_task "chef:execute:update"
126
+ def exec_execute
127
+ exec_solo
128
+ config.find_and_execute_task "chef:execute:solo"
166
129
  end
167
130
 
168
- private
131
+ def exec_update
132
+ config.find_and_execute_task "chef:execute:update"
133
+ end
169
134
 
170
135
  def config
171
136
  @config ||= prep_config
@@ -184,7 +149,15 @@ module Capstrap
184
149
  config
185
150
  end
186
151
 
187
- def setup_config(options)
152
+ def setup_config(cli_options)
153
+ abort ">> HOST must be set" unless @ssh_host
154
+
155
+ options = Hash.new
156
+ options.merge!(cli_options)
157
+ if File.exists?(options["config"])
158
+ options.merge!(YAML::load_file(options["config"]))
159
+ end
160
+
188
161
  [
189
162
  {:sym => :ruby, :opt => "ruby"},
190
163
  {:sym => :cookbooks_repo, :opt => "cookbooks-repo"},
@@ -1,3 +1,3 @@
1
1
  module Capstrap
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Fletcher Nichol
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-20 00:00:00 -07:00
18
+ date: 2010-11-21 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency