sous-chef 0.0.5 → 0.0.6
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/Gemfile.lock +1 -1
- data/README.md +38 -31
- data/lib/helpers/node_helpers.rb +10 -0
- data/lib/sous-chef/collection.rb +12 -0
- data/lib/sous-chef/node_builder.rb +27 -0
- data/lib/sous-chef/node_manager.rb +18 -0
- data/lib/sous-chef/node_tasks.rb +47 -0
- data/lib/sous-chef/task_builder.rb +25 -0
- data/lib/sous-chef/tasks.rb +1 -56
- data/lib/sous-chef.rb +26 -14
- data/lib/tasks/node_tasks.rake +4 -0
- data/lib/tasks/sous_chef.rake +7 -0
- data/lib/templates/nodes.example.yml +22 -22
- data/sous-chef.gemspec +1 -1
- data/spec/helpers/node_helpers_spec.rb +27 -0
- data/spec/sous-chef/collection_spec.rb +29 -0
- data/spec/sous-chef/node_builder_spec.rb +20 -0
- data/spec/sous-chef/node_manager_spec.rb +16 -0
- data/spec/sous-chef/node_tasks_spec.rb +20 -0
- data/spec/sous-chef/parser_spec.rb +2 -2
- data/spec/sous-chef/sous-chef_spec.rb +21 -0
- data/spec/sous-chef/task_builder_spec.rb +25 -0
- data/spec/sous-chef/tasks_spec.rb +41 -0
- data/spec/{fixtures → support/fixtures}/single_node.yml +0 -0
- data/spec/support/fixtures/some_nodes.yml +18 -0
- metadata +30 -13
- data/lib/sous-chef/environment.rb +0 -20
- data/lib/sous-chef/manager.rb +0 -20
- data/lib/tasks/sous-chef.rake +0 -2
- data/spec/fixtures/some_nodes.yml +0 -19
- data/spec/sous-chef/environment_spec.rb +0 -17
- data/spec/sous-chef/manager_spec.rb +0 -16
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -16,54 +16,61 @@ You may run `rake sous_chef:init` to generate sample `nodes.yml` to
|
|
16
16
|
## Configure
|
17
17
|
|
18
18
|
Create configuration in knife-solo nodes dir e.g. `nodes/nodes.yml`. Node
|
19
|
-
configuration is used for sshconfig as well as nodename.
|
19
|
+
configuration is used for sshconfig as well as nodename. You can namespace
|
20
|
+
nodes however you want. Example `nodes.yml`:
|
20
21
|
|
21
22
|
```yaml
|
22
23
|
# Format:
|
23
24
|
#
|
24
25
|
# <environment>:
|
25
|
-
# <
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
26
|
+
# <other-namespace>:
|
27
|
+
# <node name>:
|
28
|
+
# node_config: <knife-solo node config e.g. nodes/someNode.json>
|
29
|
+
# ssh_config:
|
30
|
+
# <ssh config options>
|
31
|
+
# e.g.
|
32
|
+
# Host: <host alias. defaults to node name>
|
33
|
+
# HostName: 12.34.56.789
|
34
|
+
# Port: 1234
|
35
|
+
# IdentityFile: ~/.ssh/other_id_rsa
|
34
36
|
|
35
37
|
production:
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
web:
|
39
|
+
SuperAwesomeNode:
|
40
|
+
node_config: nodes/some_node.json
|
41
|
+
ssh_config:
|
42
|
+
HostName: 12.34.56.789
|
43
|
+
Port 1234
|
44
|
+
IdentityFile: ~/.ssh/other_id_rsa
|
45
|
+
staging:
|
43
46
|
CoolWorld:
|
44
47
|
node_config: nodes/some_node.json
|
45
48
|
ssh_config:
|
46
49
|
HostName: localhost
|
47
50
|
|
48
51
|
vagrant:
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
ForwardAgent: "yes"
|
52
|
+
node_config: nodes/buildAgent.json
|
53
|
+
ssh_config:
|
54
|
+
HostName: 127.0.0.1
|
55
|
+
User: vagrant
|
56
|
+
Port: 2222
|
57
|
+
UserKnownHostsFile: /dev/null
|
58
|
+
StrictHostKeyChecking: "no"
|
59
|
+
PasswordAuthentication: "no"
|
60
|
+
IdentityFile: "~/.vagrant.d/insecure_private_key"
|
61
|
+
IdentitiesOnly: "yes"
|
62
|
+
ForwardAgent: "yes"
|
61
63
|
```
|
62
64
|
|
63
65
|
## Usage
|
64
66
|
|
65
67
|
`rake -T` for a full list of tasks provided:
|
66
68
|
|
67
|
-
|
68
|
-
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
1. Fork it
|
72
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
73
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
74
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
75
|
+
5. Create new Pull Request
|
69
76
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class SousChef::NodeBuilder
|
2
|
+
include SousChef::NodeHelpers
|
3
|
+
|
4
|
+
def initialize(name, collection_hash)
|
5
|
+
@name = name
|
6
|
+
@collection_hash = collection_hash
|
7
|
+
end
|
8
|
+
|
9
|
+
def build
|
10
|
+
if node?(@collection_hash)
|
11
|
+
SousChef::Node.new(@name, @collection_hash)
|
12
|
+
else
|
13
|
+
build_nodes
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def build_nodes
|
20
|
+
nodes = SousChef::Collection.new(@name)
|
21
|
+
@collection_hash.each do |name, collection_hash|
|
22
|
+
nodes[name] = SousChef::NodeBuilder.new(name, collection_hash).build
|
23
|
+
end
|
24
|
+
nodes
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class SousChef::NodeManager
|
2
|
+
attr_reader :parser, :nodes
|
3
|
+
|
4
|
+
def initialize(config_file)
|
5
|
+
@parser = SousChef::Parser.new(config_file)
|
6
|
+
@nodes = {}
|
7
|
+
initialize_node_collections
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def initialize_node_collections
|
13
|
+
@parser.parse.each do |name, collection|
|
14
|
+
@nodes[name] = SousChef::NodeBuilder.new(name, collection).build
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
module SousChef::NodeTasks
|
4
|
+
include Rake::DSL
|
5
|
+
|
6
|
+
def build_node_task(node)
|
7
|
+
namespace node.name do
|
8
|
+
prepare_task(node)
|
9
|
+
cook_task(node)
|
10
|
+
bootstrap_task(node)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def cook_task(node)
|
15
|
+
desc "Run knife solo cook for #{node.name}"
|
16
|
+
task :cook do
|
17
|
+
run_knife 'cook', node
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def bootstrap_task(node)
|
22
|
+
desc "Run knife solo bootstrap for #{node.name}"
|
23
|
+
task :bootstrap do
|
24
|
+
run_knife 'bootstrap', node
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def prepare_task(node)
|
29
|
+
desc "Run knife solo prepare for #{node.name}"
|
30
|
+
task :prepare do
|
31
|
+
run_knife 'prepare', node
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def run(command)
|
36
|
+
puts "Running: #{command}"
|
37
|
+
system command
|
38
|
+
raise "Failure! #{$?}" if $? != 0
|
39
|
+
end
|
40
|
+
|
41
|
+
def run_knife(command, node)
|
42
|
+
run "knife solo #{command} -F #{node.ssh_config_path} #{node.hostname} -N #{node.name} #{node.config}"
|
43
|
+
end
|
44
|
+
|
45
|
+
module_function :build_node_task, :cook_task, :bootstrap_task, :prepare_task, :run, :run_knife
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class SousChef::TaskBuilder
|
2
|
+
include SousChef::NodeTasks
|
3
|
+
include SousChef::NodeHelpers
|
4
|
+
|
5
|
+
def initialize(nodes)
|
6
|
+
@nodes = nodes
|
7
|
+
end
|
8
|
+
|
9
|
+
def build_tasks
|
10
|
+
build_namespace(@nodes)
|
11
|
+
end
|
12
|
+
|
13
|
+
def build_namespace(collection)
|
14
|
+
collection.each do |name, collection|
|
15
|
+
if node?(collection)
|
16
|
+
build_node_task(collection)
|
17
|
+
else
|
18
|
+
namespace name do
|
19
|
+
build_namespace(collection)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/lib/sous-chef/tasks.rb
CHANGED
@@ -1,57 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
def run(command)
|
4
|
-
puts "Running: #{command}"
|
5
|
-
system command
|
6
|
-
raise "Failure! #{$?}" if $? != 0
|
7
|
-
end
|
8
|
-
|
9
|
-
def run_knife(command, node)
|
10
|
-
run "knife solo #{command} -F #{node.ssh_config_path} #{node.hostname} -N #{node.name} #{node.config}"
|
11
|
-
end
|
12
|
-
|
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")
|
25
|
-
|
26
|
-
desc "Run knife solo bootstrap for all #{environment_name} nodes"
|
27
|
-
multitask :bootstrap => build_task_list(environment_name, env.nodes.keys, "bootstrap")
|
28
|
-
end
|
29
|
-
|
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
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
namespace :sous_chef do
|
52
|
-
desc "Generate nodes.yml example config"
|
53
|
-
task :init do
|
54
|
-
SousChef.create_config
|
55
|
-
end
|
56
|
-
end
|
1
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../tasks/*.rake")).each { |r| import r }
|
57
2
|
|
data/lib/sous-chef.rb
CHANGED
@@ -1,23 +1,35 @@
|
|
1
1
|
|
2
2
|
module SousChef
|
3
|
+
CONFIG_TEMPLATE = File.expand_path(File.join(File.dirname(__FILE__), 'templates', 'nodes.example.yml'))
|
3
4
|
CONFIG_FILE = File.join(Dir.pwd, "nodes", "nodes.yml")
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
def config_file_location
|
7
|
+
CONFIG_FILE
|
8
|
+
end
|
9
|
+
|
10
|
+
def config_template_location
|
11
|
+
CONFIG_TEMPLATE
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_config
|
15
|
+
if File.exists?(config_file_location)
|
16
|
+
puts "nodes.yml already exists"
|
17
|
+
else
|
18
|
+
puts "Coping example nodes.yml and placing in #{config_file_location}"
|
19
|
+
FileUtils.cp(config_template_location, config_file_location)
|
14
20
|
end
|
15
21
|
end
|
22
|
+
|
23
|
+
module_function :create_config, :config_file_location, :config_template_location
|
16
24
|
end
|
17
25
|
|
18
|
-
require '
|
19
|
-
require 'sous-chef/
|
20
|
-
require 'sous-chef/
|
21
|
-
require 'sous-chef/
|
22
|
-
require 'sous-chef/
|
26
|
+
require 'helpers/node_helpers'
|
27
|
+
require 'sous-chef/parser'
|
28
|
+
require 'sous-chef/node_tasks'
|
29
|
+
require 'sous-chef/node'
|
30
|
+
require 'sous-chef/collection'
|
31
|
+
require 'sous-chef/task_builder'
|
32
|
+
require 'sous-chef/node_builder'
|
33
|
+
require 'sous-chef/node_manager'
|
34
|
+
require 'sous-chef/tasks'
|
23
35
|
|
@@ -1,27 +1,27 @@
|
|
1
1
|
# Format:
|
2
2
|
#
|
3
3
|
# <environment>:
|
4
|
-
# <
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
4
|
+
# <other-namespace>:
|
5
|
+
# <node name>:
|
6
|
+
# node_config: <knife-solo node config e.g. nodes/someNode.json>
|
7
|
+
# ssh_config:
|
8
|
+
# <ssh config options>
|
9
|
+
# e.g.
|
10
|
+
# Host: <host alias. defaults to node name>
|
11
|
+
# HostName: 12.34.56.789
|
12
|
+
# Port: 1234
|
13
|
+
# IdentityFile: ~/.ssh/other_id_rsa
|
14
|
+
|
14
15
|
# vagrant:
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# ForwardAgent: "yes"
|
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"
|
27
27
|
|
data/sous-chef.gemspec
CHANGED
@@ -6,7 +6,7 @@ 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.
|
9
|
+
s.version = "0.0.6"
|
10
10
|
s.description = %q{Manage knife-solo nodes}
|
11
11
|
s.summary = %q{Manage knife-solo nodes by environment. Run knife solo
|
12
12
|
commands on one or multiple nodes.}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SousChef::NodeHelpers do
|
4
|
+
|
5
|
+
describe "#node?" do
|
6
|
+
it "should consider hashes with ssh_config key as a node" do
|
7
|
+
SousChef::NodeHelpers.node?(SousChef::Node.new({'ssh_config' => true}, {})).should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should consider hashes with node_config key as a node" do
|
11
|
+
SousChef::NodeHelpers.node?(SousChef::Node.new({'node_config' => true}, {})).should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should consider Node objects as a node" do
|
15
|
+
SousChef::NodeHelpers.node?(SousChef::Node.new('some node', {})).should be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "shouldn't consider empty hashes as a node" do
|
19
|
+
SousChef::NodeHelpers.node?({}).should be_false
|
20
|
+
end
|
21
|
+
|
22
|
+
it "shouldn't consider Collection objects as a node" do
|
23
|
+
SousChef::NodeHelpers.node?(SousChef::Collection.new('some collection')).should be_false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SousChef::Collection do
|
4
|
+
let(:nodes) { {} }
|
5
|
+
let(:collection) { SousChef::Collection.new('some collection') }
|
6
|
+
|
7
|
+
subject { collection }
|
8
|
+
|
9
|
+
describe "#initialize" do
|
10
|
+
it "should set the name" do
|
11
|
+
subject.name.should == 'some collection'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#[]= & #[]" do
|
16
|
+
it "should behave like a hash" do
|
17
|
+
subject['foo'] = {bar: 'baz'}
|
18
|
+
subject['foo'].should == {bar: 'baz'}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#has_key?" do
|
23
|
+
it "should behave like a hash" do
|
24
|
+
subject['some_key'] = true
|
25
|
+
subject.has_key?('some_key')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SousChef::NodeBuilder do
|
4
|
+
let(:node_builder) { SousChef::NodeBuilder.new('someNode', {}) }
|
5
|
+
|
6
|
+
describe "#build" do
|
7
|
+
subject { node_builder.build}
|
8
|
+
|
9
|
+
it "should return an Node instance" do
|
10
|
+
node_builder.stub(node?: true)
|
11
|
+
subject.should be_a SousChef::Node
|
12
|
+
end
|
13
|
+
|
14
|
+
it"should return a Collectyion instance" do
|
15
|
+
node_builder.stub(node?: false)
|
16
|
+
subject.should be_a SousChef::Collection
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SousChef::NodeManager do
|
4
|
+
let(:node_manager) { SousChef::NodeManager.new(File.join(SPEC_ROOT, "support", "fixtures", "some_nodes.yml")) }
|
5
|
+
|
6
|
+
describe "#initialize" do
|
7
|
+
it "instantiates a parser with the config file" do
|
8
|
+
node_manager.parser.should be_a SousChef::Parser
|
9
|
+
end
|
10
|
+
|
11
|
+
it "instantiates nodes as a hash" do
|
12
|
+
node_manager.nodes.should be_a Hash
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SousChef::NodeTasks do
|
4
|
+
before do
|
5
|
+
SousChef::NodeTasks.stub(:run)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#run_knife" do
|
9
|
+
it "should run knife solo command for given node" do
|
10
|
+
node = double('node')
|
11
|
+
node.stub(name: 'foo')
|
12
|
+
node.stub(hostname: 'node_hostname')
|
13
|
+
node.stub(ssh_config_path: 'ssh_config_path')
|
14
|
+
node.stub(config: 'knife_solo_node_config')
|
15
|
+
SousChef::NodeTasks.should_receive(:run).with("knife solo some_command -F ssh_config_path node_hostname -N foo knife_solo_node_config")
|
16
|
+
SousChef::NodeTasks.run_knife('some_command', node)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -10,10 +10,10 @@ describe SousChef::Parser do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "#parse" do
|
13
|
-
subject { SousChef::Parser.new(File.join(SPEC_ROOT, "fixtures", "some_nodes.yml")).parse }
|
13
|
+
subject { SousChef::Parser.new(File.join(SPEC_ROOT, "support", "fixtures", "some_nodes.yml")).parse }
|
14
14
|
|
15
15
|
it "parses yaml" do
|
16
|
-
subject.
|
16
|
+
subject.should be_a Hash
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SousChef do
|
4
|
+
describe "#create_config" do
|
5
|
+
let(:template_location) { SousChef::CONFIG_TEMPLATE }
|
6
|
+
let(:config_location) { SousChef::CONFIG_FILE }
|
7
|
+
|
8
|
+
it "should copy nodes.yml if none exist" do
|
9
|
+
File.stub(exists?: false)
|
10
|
+
FileUtils.should_receive(:cp).with(template_location, config_location)
|
11
|
+
SousChef.create_config
|
12
|
+
end
|
13
|
+
|
14
|
+
it "shouldn't copy nodes.yml if one already exists" do
|
15
|
+
File.stub(exists?: true)
|
16
|
+
FileUtils.should_not_receive(:cp).with(template_location, config_location)
|
17
|
+
SousChef.create_config
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SousChef::TaskBuilder do
|
4
|
+
let(:node_collection) do
|
5
|
+
nodes = SousChef::Collection.new("web")
|
6
|
+
nodes['other_node'] = SousChef::Node.new("other_node", {})
|
7
|
+
nodes
|
8
|
+
end
|
9
|
+
let(:node) { SousChef::Node.new("nodetastic", {}) }
|
10
|
+
let(:collection) { { node.name => node, node_collection.name => node_collection} }
|
11
|
+
let(:builder) { SousChef::TaskBuilder.new(collection) }
|
12
|
+
|
13
|
+
describe "#build_namespace" do
|
14
|
+
it "should call #build_node_task for nodes" do
|
15
|
+
builder.should_receive(:build_node_task).twice
|
16
|
+
builder.build_namespace(collection)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should call #build_namespace for each Collection" do
|
20
|
+
builder.should_receive(:build_namespace).once
|
21
|
+
builder.build_namespace(collection)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "sous_chef.rake" do
|
4
|
+
before(:all) do
|
5
|
+
@rake = Rake::Application.new
|
6
|
+
Rake.application = @rake
|
7
|
+
@rake.rake_require "lib/tasks/sous_chef", [File.expand_path(File.join(SPEC_ROOT, '..'))]
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should have sous_chef:init rake task" do
|
11
|
+
rake_tasks = @rake.tasks.map(&:name)
|
12
|
+
rake_tasks.should include "sous_chef:init"
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#sous_chef:init" do
|
16
|
+
it "should call #SousChef.create_config" do
|
17
|
+
SousChef.should_receive(:create_config)
|
18
|
+
@rake['sous_chef:init'].invoke
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "generated node tasks" do
|
24
|
+
let(:rake_tasks) { @rake.tasks.map(&:name) }
|
25
|
+
|
26
|
+
before(:all) do
|
27
|
+
SousChef.stub(config_file_location: File.join(SPEC_ROOT, "support", "fixtures", "some_nodes.yml"))
|
28
|
+
@rake = Rake::Application.new
|
29
|
+
Rake.application = @rake
|
30
|
+
@rake.rake_require "lib/tasks/node_tasks", [File.expand_path(File.join(SPEC_ROOT, '..'))]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should build tasks for nodes in nodes.yml" do
|
34
|
+
rake_tasks.should include "vagrant:bootstrap"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should namespace nodes tasks" do
|
38
|
+
rake_tasks.should include "production:web:OtherAwesome:bootstrap"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
production:
|
2
|
+
web:
|
3
|
+
OtherAwesome:
|
4
|
+
node_config: some/path/to/node/config
|
5
|
+
ssh_config:
|
6
|
+
HostName: localhost
|
7
|
+
CoolWorld:
|
8
|
+
node_config: some/path/to/node/config
|
9
|
+
ssh_config:
|
10
|
+
HostName: Some Ip
|
11
|
+
|
12
|
+
vagrant:
|
13
|
+
node_config: some/path/to/node/config
|
14
|
+
ssh_config:
|
15
|
+
HostName: 12.34.56.789
|
16
|
+
Port: 1234
|
17
|
+
IdentityFile: ~/.ssh/other_id_rsa
|
18
|
+
|
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
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -102,22 +102,33 @@ files:
|
|
102
102
|
- Gemfile.lock
|
103
103
|
- README.md
|
104
104
|
- Rakefile
|
105
|
+
- lib/helpers/node_helpers.rb
|
105
106
|
- lib/sous-chef.rb
|
106
|
-
- lib/sous-chef/
|
107
|
-
- lib/sous-chef/manager.rb
|
107
|
+
- lib/sous-chef/collection.rb
|
108
108
|
- lib/sous-chef/node.rb
|
109
|
+
- lib/sous-chef/node_builder.rb
|
110
|
+
- lib/sous-chef/node_manager.rb
|
111
|
+
- lib/sous-chef/node_tasks.rb
|
109
112
|
- lib/sous-chef/parser.rb
|
113
|
+
- lib/sous-chef/task_builder.rb
|
110
114
|
- lib/sous-chef/tasks.rb
|
111
|
-
- lib/tasks/
|
115
|
+
- lib/tasks/node_tasks.rake
|
116
|
+
- lib/tasks/sous_chef.rake
|
112
117
|
- lib/templates/nodes.example.yml
|
113
118
|
- sous-chef.gemspec
|
114
|
-
- spec/
|
115
|
-
- spec/
|
116
|
-
- spec/sous-chef/
|
117
|
-
- spec/sous-chef/
|
119
|
+
- spec/helpers/node_helpers_spec.rb
|
120
|
+
- spec/sous-chef/collection_spec.rb
|
121
|
+
- spec/sous-chef/node_builder_spec.rb
|
122
|
+
- spec/sous-chef/node_manager_spec.rb
|
118
123
|
- spec/sous-chef/node_spec.rb
|
124
|
+
- spec/sous-chef/node_tasks_spec.rb
|
119
125
|
- spec/sous-chef/parser_spec.rb
|
126
|
+
- spec/sous-chef/sous-chef_spec.rb
|
127
|
+
- spec/sous-chef/task_builder_spec.rb
|
128
|
+
- spec/sous-chef/tasks_spec.rb
|
120
129
|
- spec/spec_helper.rb
|
130
|
+
- spec/support/fixtures/single_node.yml
|
131
|
+
- spec/support/fixtures/some_nodes.yml
|
121
132
|
homepage: http://github.com/substantial/sous-chef
|
122
133
|
licenses:
|
123
134
|
- MIT
|
@@ -145,10 +156,16 @@ specification_version: 3
|
|
145
156
|
summary: Manage knife-solo nodes by environment. Run knife solo commands on one or
|
146
157
|
multiple nodes.
|
147
158
|
test_files:
|
148
|
-
- spec/
|
149
|
-
- spec/
|
150
|
-
- spec/sous-chef/
|
151
|
-
- spec/sous-chef/
|
159
|
+
- spec/helpers/node_helpers_spec.rb
|
160
|
+
- spec/sous-chef/collection_spec.rb
|
161
|
+
- spec/sous-chef/node_builder_spec.rb
|
162
|
+
- spec/sous-chef/node_manager_spec.rb
|
152
163
|
- spec/sous-chef/node_spec.rb
|
164
|
+
- spec/sous-chef/node_tasks_spec.rb
|
153
165
|
- spec/sous-chef/parser_spec.rb
|
166
|
+
- spec/sous-chef/sous-chef_spec.rb
|
167
|
+
- spec/sous-chef/task_builder_spec.rb
|
168
|
+
- spec/sous-chef/tasks_spec.rb
|
154
169
|
- spec/spec_helper.rb
|
170
|
+
- spec/support/fixtures/single_node.yml
|
171
|
+
- spec/support/fixtures/some_nodes.yml
|
@@ -1,20 +0,0 @@
|
|
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
|
-
|
data/lib/sous-chef/manager.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module SousChef
|
2
|
-
class Manager
|
3
|
-
attr_reader :envs, :parser
|
4
|
-
|
5
|
-
def initialize(config_file)
|
6
|
-
@parser = Parser.new(config_file)
|
7
|
-
@envs = {}
|
8
|
-
initialize_environments
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
def initialize_environments
|
14
|
-
@parser.parse.each do |name, nodes|
|
15
|
-
@envs[name] = Environment.new(name, nodes)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
data/lib/tasks/sous-chef.rake
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
production:
|
2
|
-
OtherAwesome:
|
3
|
-
node_config: some/path/to/node/config
|
4
|
-
ssh_config:
|
5
|
-
HostName: localhost
|
6
|
-
|
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
|
19
|
-
|
@@ -1,17 +0,0 @@
|
|
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
|
-
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe SousChef::Manager do
|
4
|
-
let(:manager) { SousChef::Manager.new(File.join(SPEC_ROOT, "fixtures", "some_nodes.yml")) }
|
5
|
-
|
6
|
-
describe "#initialize" do
|
7
|
-
it "instantiates a parser with the config file" do
|
8
|
-
manager.parser.should be_a SousChef::Parser
|
9
|
-
end
|
10
|
-
|
11
|
-
it "has environments" do
|
12
|
-
manager.envs.should be_a Hash
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|