sous-chef 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sous-chef (0.0.3)
4
+ sous-chef (0.0.4)
5
5
  knife-solo (~> 0.1.0)
6
6
  rake (~> 10.0.3)
7
7
 
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # Sous Chef
2
2
 
3
- Note: This gem is a work in progress.
4
-
5
3
  Manage [knife-solo](http://matschaffer.github.com/knife-solo/) nodes.
6
4
 
7
5
  ## Install
@@ -12,7 +10,8 @@ Add the following to your `Rakefile`:
12
10
  require 'sous-chef'
13
11
  ```
14
12
 
15
- You may run `rake sous_chef` to generate sample `nodes.yml` to `nodes/nodes.yml`
13
+ You may run `rake sous_chef:init` to generate sample `nodes.yml` to
14
+ `nodes/nodes.yml`
16
15
 
17
16
  ## Configure
18
17
 
@@ -22,31 +21,49 @@ configuration is used for sshconfig as well as nodename. Example `nodes.yml`:
22
21
  ```yaml
23
22
  # Format:
24
23
  #
25
- # <node name>:
26
- # node_config: <knife-solo node config e.g. nodes/someNode.json>
27
- # ssh_config:
28
- # <ssh config options>
29
- # e.g.
30
- # Host: <host alias. defaults to node name>
31
- # HostName: 12.34.56.789
32
- # Port: 1234
33
- # IdentityFile: ~/.ssh/other_id_rsa
34
- #
24
+ # <environment>:
25
+ # <node name>:
26
+ # node_config: <knife-solo node config e.g. nodes/someNode.json>
27
+ # ssh_config:
28
+ # <ssh config options>
29
+ # e.g.
30
+ # Host: <host alias. defaults to node name>
31
+ # HostName: 12.34.56.789
32
+ # Port: 1234
33
+ # IdentityFile: ~/.ssh/other_id_rsa
34
+
35
+ production:
36
+ SuperAwesomeNode:
37
+ node_config: nodes/some_node.json
38
+ ssh_config:
39
+ HostName: 12.34.56.789
40
+ Port 1234
41
+ IdentityFile: ~/.ssh/other_id_rsa
35
42
 
36
- SuperAwesomeNode:
37
- node_config: nodes/some_node.json
38
- ssh_config:
39
- HostName: 12.34.56.789
40
- Port 1234
41
- IdentityFile: ~/.ssh/other_id_rsa
42
-
43
- OtherAwesome:
44
- node_config: nodes/some_node.json
45
- ssh_config:
46
- HostName: 12.34.56.789
43
+ CoolWorld:
44
+ node_config: nodes/some_node.json
45
+ ssh_config:
46
+ HostName: localhost
47
+
48
+ vagrant:
49
+ default:
50
+ node_config: nodes/buildAgent.json
51
+ ssh_config:
52
+ HostName: 127.0.0.1
53
+ User: vagrant
54
+ Port: 2222
55
+ UserKnownHostsFile: /dev/null
56
+ StrictHostKeyChecking: "no"
57
+ PasswordAuthentication: "no"
58
+ IdentityFile: "~/.vagrant.d/insecure_private_key"
59
+ IdentitiesOnly: "yes"
60
+ ForwardAgent: "yes"
47
61
  ```
48
62
 
49
63
  ## Usage
50
64
 
51
65
  `rake -T` for a full list of tasks provided:
52
66
 
67
+ `rake <environment>:all:<knife solo task>` will run on all nodes for a given
68
+ environment.
69
+
@@ -0,0 +1,20 @@
1
+ module SousChef
2
+ class Environment
3
+ attr_reader :nodes, :name
4
+
5
+ def initialize(name, nodes)
6
+ @nodes = {}
7
+ @name = name
8
+ initialize_nodes(nodes)
9
+ end
10
+
11
+ private
12
+
13
+ def initialize_nodes(nodes)
14
+ nodes.each do |name, settings|
15
+ @nodes[name] = Node.new(name, settings)
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -1,25 +1,20 @@
1
1
  module SousChef
2
2
  class Manager
3
- attr_accessor :nodes
4
- attr_reader :parser
3
+ attr_reader :envs, :parser
5
4
 
6
5
  def initialize(config_file)
7
6
  @parser = Parser.new(config_file)
8
- @nodes = {}
9
- initialize_nodes
10
- end
11
-
12
- def all
13
- @nodes.keys
7
+ @envs = {}
8
+ initialize_environments
14
9
  end
15
10
 
16
11
  private
17
12
 
18
- def initialize_nodes
19
- @parser.parse.each do |node, settings|
20
- @nodes[node] = Node.new(node, settings)
13
+ def initialize_environments
14
+ @parser.parse.each do |name, nodes|
15
+ @envs[name] = Environment.new(name, nodes)
21
16
  end
22
17
  end
23
-
24
18
  end
25
19
  end
20
+
@@ -3,9 +3,9 @@ class SousChef::Node
3
3
 
4
4
  require 'tempfile'
5
5
 
6
- def initialize(node, settings)
6
+ def initialize(name, settings)
7
7
  @settings = settings
8
- @name = node
8
+ @name = name
9
9
  end
10
10
 
11
11
  def config
@@ -10,27 +10,48 @@ def run_knife(command, node)
10
10
  run "knife solo #{command} -F #{node.ssh_config_path} #{node.hostname} -N #{node.name} #{node.config}"
11
11
  end
12
12
 
13
- SousChef::Manager.new(SousChef::CONFIG_FILE).nodes.each do |name, node|
14
- namespace name do
15
- desc "Run knife solo prepare for #{name}"
16
- task :prepare do
17
- run_knife 'prepare', node
18
- end
13
+ def build_task_list(environment_name, names, task)
14
+ names.map { |name| "#{environment_name}:#{name}:#{task}" }
15
+ end
16
+
17
+ SousChef::Manager.new(SousChef::CONFIG_FILE).envs.each do |environment_name, env|
18
+ namespace environment_name do
19
+ namespace :all do
20
+ desc "Run knife solo prepare for all #{environment_name} nodes"
21
+ multitask :prepare => build_task_list(environment_name, env.nodes.keys, "prepare")
22
+
23
+ desc "Run knife solo cook for all #{environment_name} nodes"
24
+ multitask :cook => build_task_list(environment_name, env.nodes.keys, "cook")
19
25
 
20
- desc "Run knife solo cook for #{name}"
21
- task :cook do
22
- run_knife 'cook', node
26
+ desc "Run knife solo bootstrap for all #{environment_name} nodes"
27
+ multitask :bootstrap => build_task_list(environment_name, env.nodes.keys, "bootstrap")
23
28
  end
24
29
 
25
- desc "Run knife solo bootstrap for #{name}"
26
- task :bootstrap do
27
- run_knife 'bootstrap', node
30
+ env.nodes.each do |node_name, node|
31
+ namespace node_name do
32
+ desc "Run knife solo prepare for #{node_name}"
33
+ task :prepare do
34
+ run_knife 'prepare', node
35
+ end
36
+
37
+ desc "Run knife solo cook for #{node_name}"
38
+ task :cook do
39
+ run_knife 'cook', node
40
+ end
41
+
42
+ desc "Run knife solo bootstrap for #{node_name}"
43
+ task :bootstrap do
44
+ run_knife 'bootstrap', node
45
+ end
46
+ end
28
47
  end
29
48
  end
30
49
  end
31
50
 
32
- desc "Generate nodes.yml example config"
33
- task :sous_chef do
34
- SousChef.create_config
51
+ namespace :sous_chef do
52
+ desc "Generate nodes.yml example config"
53
+ task :init do
54
+ SousChef.create_config
55
+ end
35
56
  end
36
57
 
data/lib/sous-chef.rb CHANGED
@@ -17,6 +17,7 @@ end
17
17
 
18
18
  require 'sous-chef/parser.rb'
19
19
  require 'sous-chef/node.rb'
20
+ require 'sous-chef/environment.rb'
20
21
  require 'sous-chef/manager.rb'
21
22
  require 'sous-chef/tasks.rb'
22
23
 
@@ -1,13 +1,27 @@
1
1
  # Format:
2
2
  #
3
- # <node name>:
4
- # node_config: <knife-solo node config e.g. nodes/someNode.json>
5
- # ssh_config:
6
- # <ssh config options>
7
- # e.g.
8
- # Host: <host alias. defaults to node name>
9
- # HostName: 12.34.56.789
10
- # Port: 1234
11
- # IdentityFile: ~/.ssh/other_id_rsa
3
+ # <environment>:
4
+ # <node name>:
5
+ # node_config: <knife-solo node config e.g. nodes/someNode.json>
6
+ # ssh_config:
7
+ # <ssh config options>
8
+ # e.g.
9
+ # Host: <host alias. defaults to node name>
10
+ # HostName: 12.34.56.789
11
+ # Port: 1234
12
+ # IdentityFile: ~/.ssh/other_id_rsa
12
13
  #
14
+ # vagrant:
15
+ # default:
16
+ # node_config: nodes/buildAgent.json
17
+ # ssh_config:
18
+ # HostName: 127.0.0.1
19
+ # User: vagrant
20
+ # Port: 2222
21
+ # UserKnownHostsFile: /dev/null
22
+ # StrictHostKeyChecking: "no"
23
+ # PasswordAuthentication: "no"
24
+ # IdentityFile: "~/.vagrant.d/insecure_private_key"
25
+ # IdentitiesOnly: "yes"
26
+ # ForwardAgent: "yes"
13
27
 
data/sous-chef.gemspec CHANGED
@@ -6,9 +6,10 @@ Gem::Specification.new do |s|
6
6
  s.email = "shaun@substantail.com"
7
7
 
8
8
  s.name = 'sous-chef'
9
- s.version = "0.0.4"
9
+ s.version = "0.0.5"
10
10
  s.description = %q{Manage knife-solo nodes}
11
- s.summary = %q{Manage knife-solo nodes}
11
+ s.summary = %q{Manage knife-solo nodes by environment. Run knife solo
12
+ commands on one or multiple nodes.}
12
13
  s.homepage = %q{http://github.com/substantial/sous-chef}
13
14
  s.license = "MIT"
14
15
 
@@ -1,12 +1,19 @@
1
- SuperAwesomeNode:
2
- node_config: some/path/to/node/config
3
- ssh_config:
4
- HostName: 12.34.56.789
5
- Port: 1234
6
- IdentityFile: ~/.ssh/other_id_rsa
1
+ production:
2
+ OtherAwesome:
3
+ node_config: some/path/to/node/config
4
+ ssh_config:
5
+ HostName: localhost
7
6
 
8
- OtherAwesome:
9
- node_config: some/path/to/node/config
10
- ssh_config:
11
- HostName: localhost
7
+ CoolWorld:
8
+ node_config: some/path/to/node/config
9
+ ssh_config:
10
+ HostName: Some Ip
11
+
12
+ staging:
13
+ AwesomeDBServer:
14
+ node_config: some/path/to/node/config
15
+ ssh_config:
16
+ HostName: 12.34.56.789
17
+ Port: 1234
18
+ IdentityFile: ~/.ssh/other_id_rsa
12
19
 
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe SousChef::Environment do
4
+ let(:nodes) { {} }
5
+ let(:environment) { SousChef::Environment.new('some environment', nodes) }
6
+
7
+ describe "#initialize" do
8
+ it "sets the name" do
9
+ environment.name.should == 'some environment'
10
+ end
11
+
12
+ it "has nodes" do
13
+ environment.nodes.should be_a Hash
14
+ end
15
+ end
16
+ end
17
+
@@ -8,14 +8,8 @@ describe SousChef::Manager do
8
8
  manager.parser.should be_a SousChef::Parser
9
9
  end
10
10
 
11
- it "instantiates nodes" do
12
- manager.nodes.should be_a Hash
13
- end
14
- end
15
-
16
- describe "#all" do
17
- it "returns node names" do
18
- manager.all.should =~ %w[SuperAwesomeNode OtherAwesome]
11
+ it "has environments" do
12
+ manager.envs.should be_a Hash
19
13
  end
20
14
  end
21
15
  end
@@ -13,7 +13,7 @@ describe SousChef::Parser do
13
13
  subject { SousChef::Parser.new(File.join(SPEC_ROOT, "fixtures", "some_nodes.yml")).parse }
14
14
 
15
15
  it "parses yaml" do
16
- subject.keys.should =~ %w[SuperAwesomeNode OtherAwesome]
16
+ subject.keys.should =~ %w[production staging]
17
17
  end
18
18
  end
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sous-chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -103,6 +103,7 @@ files:
103
103
  - README.md
104
104
  - Rakefile
105
105
  - lib/sous-chef.rb
106
+ - lib/sous-chef/environment.rb
106
107
  - lib/sous-chef/manager.rb
107
108
  - lib/sous-chef/node.rb
108
109
  - lib/sous-chef/parser.rb
@@ -112,6 +113,7 @@ files:
112
113
  - sous-chef.gemspec
113
114
  - spec/fixtures/single_node.yml
114
115
  - spec/fixtures/some_nodes.yml
116
+ - spec/sous-chef/environment_spec.rb
115
117
  - spec/sous-chef/manager_spec.rb
116
118
  - spec/sous-chef/node_spec.rb
117
119
  - spec/sous-chef/parser_spec.rb
@@ -140,10 +142,12 @@ rubyforge_project: sous-chef
140
142
  rubygems_version: 1.8.24
141
143
  signing_key:
142
144
  specification_version: 3
143
- summary: Manage knife-solo nodes
145
+ summary: Manage knife-solo nodes by environment. Run knife solo commands on one or
146
+ multiple nodes.
144
147
  test_files:
145
148
  - spec/fixtures/single_node.yml
146
149
  - spec/fixtures/some_nodes.yml
150
+ - spec/sous-chef/environment_spec.rb
147
151
  - spec/sous-chef/manager_spec.rb
148
152
  - spec/sous-chef/node_spec.rb
149
153
  - spec/sous-chef/parser_spec.rb