capstrap 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Fletcher Nichol
1
+ Copyright (c) 2010 Fletcher Nichol
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.markdown ADDED
@@ -0,0 +1,73 @@
1
+ # capstrap
2
+
3
+ A command to remotely install git, rvm, ruby, and chef-solo using capistrano.
4
+
5
+ To get started, install capstrap:
6
+
7
+ gem install capstrap
8
+
9
+ capstrap assumes you are operating as *root* so you might want to drop in
10
+ your ssh key to root's *authorized_keys*:
11
+
12
+ ssh root@zland '(if [ ! -d "${HOME}/.ssh" ]; then \
13
+ mkdir -m 0700 -p ${HOME}/.ssh; fi; \
14
+ cat - >> .ssh/authorized_keys)' < ${HOME}/.ssh/id_dsa.pub
15
+
16
+ To install a baseline RVM/ruby environment (*ree-1.8.7* is default):
17
+
18
+ capstrap ruby root@zland
19
+
20
+ To use a custom RVM ruby:
21
+
22
+ capstrap ruby root@zland --ruby=ruby-1.8.7
23
+
24
+ To install the *chef* gem:
25
+
26
+ capstrap chef root@zland
27
+
28
+ To install a chef cookbooks repository and chef configuration:
29
+
30
+ capstrap solo root@zland \
31
+ --cookbooks-repo=git://github.com/fnichol/chef-repo.git \
32
+ --config-repo=git://github.com/fnichol/chef-dna-spike.git
33
+
34
+ To override the default cookbooks and configuration paths:
35
+
36
+ capstrap solo root@zland \
37
+ --cookbooks-repo=git://github.com/fnichol/chef-repo.git \
38
+ --cookbooks-path=/opt/chef \
39
+ --config-repo=git://github.com/fnichol/chef-dna-spike.git \
40
+ --config-path=/opt/chef/config
41
+
42
+ To execute a chef configuration (the full monty):
43
+
44
+ capstrap execute root@zland \
45
+ --cookbooks-repo=git://github.com/fnichol/chef-repo.git \
46
+ --config-repo=git://github.com/fnichol/chef-dna-spike.git
47
+
48
+ To set some other crazy configuration (the full monty with cheese):
49
+
50
+ capstrap execute root@zland \
51
+ --ruby=ruby-1.8.7 \
52
+ --cookbooks-repo=git://github.com/fnichol/chef-repo.git \
53
+ --cookbooks-path=/opt/chef \
54
+ --config-repo=git://github.com/fnichol/chef-dna-spike.git \
55
+ --config-path=/opt/chef/config
56
+
57
+ To get more help:
58
+
59
+ capstrap help
60
+
61
+ ## Note on Patches/Pull Requests
62
+
63
+ * Fork the project.
64
+ * Make your feature addition or bug fix.
65
+ * Add tests for it. This is important so I don't break it in a
66
+ future version unintentionally.
67
+ * Commit, do not mess with rakefile, version, or history.
68
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
69
+ * Send me a pull request. Bonus points for topic branches.
70
+
71
+ ## Copyright
72
+
73
+ Copyright (c) 2010 Fletcher Nichol. See LICENSE for details.
@@ -7,11 +7,51 @@ module Capstrap
7
7
  namespace :chef do
8
8
  namespace :install do
9
9
 
10
- desc "Installs chef solo"
10
+ desc "Installs chef gem"
11
+ task :lib do
12
+ unless chef_installed?
13
+ cmd = [
14
+ %{use #{ruby}@global},
15
+ %{gem install chef}
16
+ ]
17
+ rvm_run cmd.join(" && ")
18
+ end
19
+ end
20
+
21
+ desc "Installs chef cookbook git repository"
22
+ task :cookbooks do
23
+ unless cookbooks_repo_installed?
24
+ cmd = [
25
+ %{git clone #{cookbooks_repo} #{cookbooks_path}},
26
+ %{cd #{cookbooks_path}},
27
+ %{git submodule init},
28
+ %{git submodule update}
29
+ ]
30
+ run cmd.join(" && ")
31
+ end
32
+ end
33
+
34
+ desc "Installs chef configuration git repository"
35
+ task :config do
36
+ unless config_repo_installed?
37
+ cmd = [
38
+ %{git clone #{config_repo} #{config_path}},
39
+ %{cd #{config_path}},
40
+ %{git submodule init},
41
+ %{git submodule update}
42
+ ]
43
+ run cmd.join(" && ")
44
+ end
45
+ end
46
+ end
47
+
48
+ namespace :execute do
49
+
50
+ desc "Executes chef solo configuration"
11
51
  task :solo do
12
52
  cmd = [
13
- %{use default@global},
14
- %{gem install chef}
53
+ %{use #{ruby}},
54
+ %{chef-solo}
15
55
  ]
16
56
  rvm_run cmd.join(" && ")
17
57
  end
@@ -5,8 +5,8 @@
5
5
  # @return [true, false] whether or not the conditional passes
6
6
  def cmd_if(test, rvm=false)
7
7
  load_rvm = ""
8
- load_rvm = rvm_env
9
- r = capture %{#{rvm_env} if #{test} ; then echo true; else echo false; fi},
8
+ load_rvm = "#{rvm_env} " if rvm
9
+ r = capture %{#{load_rvm}if #{test} ; then echo true; else echo false; fi},
10
10
  :shell => "bash"
11
11
  puts " * Result is: #{r.to_s}"
12
12
  if r.to_s =~ /true/
@@ -73,6 +73,28 @@ def ruby_installed?(ruby)
73
73
  cmd_if %{rvm list strings | grep -q "#{ruby}" >/dev/null}, true
74
74
  end
75
75
 
76
+ ##
77
+ # Checks if the chef gem is installed on the remote host.
78
+ #
79
+ def chef_installed?
80
+ cmd_if %{rvm use #{ruby}@global >/dev/null && gem list --no-versions | grep -q "^chef$" >/dev/null}, true
81
+ end
82
+
83
+
84
+ ##
85
+ # Checks if chef cookbook repo is installed on the remote host.
86
+ #
87
+ def cookbooks_repo_installed?
88
+ cmd_test %{-d "#{cookbooks_path}"}
89
+ end
90
+
91
+ ##
92
+ # Checks if chef config repo is installed on the remote host.
93
+ #
94
+ def config_repo_installed?
95
+ cmd_test %{-d "#{config_path}"}
96
+ end
97
+
76
98
  ##
77
99
  # Prints an information message.
78
100
  #
data/lib/capstrap/cli.rb CHANGED
@@ -16,21 +16,90 @@ module Capstrap
16
16
  @ssh_host = ssh_host
17
17
  abort ">> HOST must be set" unless @ssh_host
18
18
 
19
+ setup_config options
20
+
19
21
  config.find_and_execute_task "rvm:install:#{options[:ruby]}"
20
22
  if options[:default]
21
23
  config.find_and_execute_task "rvm:default:#{options[:ruby]}"
22
24
  end
23
25
  end
24
26
 
25
- desc "chefsolo HOST", "Install chef solo on remote SSH host HOST"
27
+ desc "chef HOST", "Install chef gem on remote SSH host HOST"
26
28
  method_option "ruby", :type => :string, :banner =>
27
29
  "Version of ruby to install.", :default => "ree-1.8.7"
28
- def chefsolo(ssh_host)
30
+ def chef(ssh_host)
29
31
  @ssh_host = ssh_host
30
32
  abort ">> HOST must be set" unless @ssh_host
31
33
 
34
+ setup_config options
35
+
32
36
  invoke :ruby, [ssh_host], :ruby => options[:ruby], :default => true
33
- config.find_and_execute_task "chef:install:solo"
37
+ config.find_and_execute_task "chef:install:lib"
38
+ end
39
+
40
+ desc "solo HOST", "Install chef cookbooks & config on remote SSH host HOST"
41
+ method_option "ruby", :type => :string, :banner =>
42
+ "Version of ruby to install.", :default => "ree-1.8.7"
43
+ method_option "cookbooks-repo", :type => :string, :banner =>
44
+ "Chef cookbooks git repository URL."
45
+ method_option "cookbooks-path", :type => :string,
46
+ :banner => "Install path to chef cookbooks git repository.",
47
+ :default => "/var/chef-solo"
48
+ method_option "config-repo", :type => :string, :banner =>
49
+ "Chef configuration git repository URL."
50
+ method_option "config-path", :type => :string,
51
+ :banner => "Install path to chef configuration git repository.",
52
+ :default => "/etc/chef"
53
+ def solo(ssh_host)
54
+ @ssh_host = ssh_host
55
+ abort ">> HOST must be set" unless @ssh_host
56
+
57
+ setup_config options
58
+
59
+ unless options["cookbooks-repo"]
60
+ abort ">> --cookbooks-repo=<git_url> must be set"
61
+ end
62
+ unless options["config-repo"]
63
+ abort ">> --config-repo=<git_url> must be set"
64
+ end
65
+
66
+ invoke :chef, [ssh_host], :ruby => options[:ruby], :default => true
67
+ config.find_and_execute_task "chef:install:cookbooks"
68
+ config.find_and_execute_task "chef:install:config"
69
+ end
70
+
71
+ desc "execute HOST", "Executes chef solo config on remote SSH host HOST"
72
+ method_option "ruby", :type => :string, :banner =>
73
+ "Version of ruby to install.", :default => "ree-1.8.7"
74
+ method_option "cookbooks-repo", :type => :string, :banner =>
75
+ "Chef cookbooks git repository URL."
76
+ method_option "cookbooks-path", :type => :string,
77
+ :banner => "Install path to chef cookbooks git repository.",
78
+ :default => "/var/chef-solo"
79
+ method_option "config-repo", :type => :string, :banner =>
80
+ "Chef configuration git repository URL."
81
+ method_option "config-path", :type => :string,
82
+ :banner => "Install path to chef configuration git repository.",
83
+ :default => "/etc/chef"
84
+ def execute(ssh_host)
85
+ @ssh_host = ssh_host
86
+ abort ">> HOST must be set" unless @ssh_host
87
+
88
+ setup_config options
89
+
90
+ unless options["cookbooks-repo"]
91
+ abort ">> --cookbooks-repo=<git_url> must be set"
92
+ end
93
+ unless options["config-repo"]
94
+ abort ">> --config-repo=<git_url> must be set"
95
+ end
96
+
97
+ invoke :solo, [ssh_host], :ruby => options[:ruby], :default => true,
98
+ :"cookbooks-repo" => options["cookbooks-repo"],
99
+ :"cookbooks-path" => options["cookbooks-path"],
100
+ :"config-repo" => options["config-repo"],
101
+ :"config-path" => options["config-path"]
102
+ config.find_and_execute_task "chef:execute:solo"
34
103
  end
35
104
 
36
105
  private
@@ -51,5 +120,17 @@ module Capstrap
51
120
 
52
121
  config
53
122
  end
123
+
124
+ def setup_config(options)
125
+ [
126
+ {:sym => :ruby, :opt => "ruby"},
127
+ {:sym => :cookbooks_repo, :opt => "cookbooks-repo"},
128
+ {:sym => :cookbooks_path, :opt => "cookbooks-path"},
129
+ {:sym => :config_repo, :opt => "config-repo"},
130
+ {:sym => :config_path, :opt => "config-path"}
131
+ ].each do |var|
132
+ config.set(var[:sym], options[var[:opt]]) if options[var[:opt]]
133
+ end
134
+ end
54
135
  end
55
136
  end
@@ -1,3 +1,3 @@
1
1
  module Capstrap
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capstrap
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.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-10-21 00:00:00 -06:00
18
+ date: 2010-10-30 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -82,7 +82,7 @@ files:
82
82
  - Gemfile
83
83
  - Gemfile.lock
84
84
  - LICENSE
85
- - README.rdoc
85
+ - README.markdown
86
86
  - Rakefile
87
87
  - bin/capstrap
88
88
  - capstrap.gemspec
data/README.rdoc DELETED
@@ -1,17 +0,0 @@
1
- = capstrap
2
-
3
- Description goes here.
4
-
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2010 Fletcher Nichol. See LICENSE for details.