capistrano-chef 0.0.4 → 0.0.5
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/README.md +1 -1
- data/capistrano-chef.gemspec +1 -1
- data/lib/capistrano/chef/version.rb +1 -1
- data/lib/capistrano/chef.rb +13 -1
- data/spec/capistrano/chef_spec.rb +30 -9
- metadata +6 -6
data/README.md
CHANGED
@@ -46,7 +46,7 @@ The `limit` attribute of the options hash will make it so only that the given nu
|
|
46
46
|
|
47
47
|
Chef [Data Bags](http://wiki.opscode.com/display/chef/Data+Bags) let you store arbitrary JSON data. A common pattern is to use an _apps_ data bag to store data about an application for use in configuration and deployment.
|
48
48
|
|
49
|
-
Chef also has a [Deploy Resource](http://wiki.opscode.com/display/chef/Deploy+Resource) described in
|
49
|
+
Chef also has a [Deploy Resource](http://wiki.opscode.com/display/chef/Deploy+Resource) described in one of their blog posts, [Data Driven Application Deployment with Chef](http://www.opscode.com/blog/2010/05/06/data-driven-application-deployment-with-chef/). This is one method of deploying, but, if you're reading this, you're probably interested in deploying with Capistrano.
|
50
50
|
|
51
51
|
If you create an _apps_ data bag item (let's call it _myapp_), Capistrano Chef will let you use the data in your Capistrano recipes with the `set_from_data_bag` method.
|
52
52
|
|
data/capistrano-chef.gemspec
CHANGED
@@ -20,5 +20,5 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
21
|
s.require_paths = ["lib"]
|
22
22
|
s.add_dependency 'capistrano', '>= 2'
|
23
|
-
s.add_dependency 'chef', '>= 0.10.
|
23
|
+
s.add_dependency 'chef', '>= 0.10.10'
|
24
24
|
end
|
data/lib/capistrano/chef.rb
CHANGED
@@ -23,7 +23,7 @@ module Capistrano::Chef
|
|
23
23
|
iface, family = arg.keys.first.to_s, arg.values.first.to_s
|
24
24
|
Proc.new do |n|
|
25
25
|
addresses = n["network"]["interfaces"][iface]["addresses"]
|
26
|
-
addresses.select{|address, data| data["family"] == family }.
|
26
|
+
addresses.select{|address, data| data["family"] == family }.to_a.first.first
|
27
27
|
end
|
28
28
|
when Symbol, String
|
29
29
|
Proc.new{|n| n[arg.to_s]}
|
@@ -37,12 +37,17 @@ module Capistrano::Chef
|
|
37
37
|
Chef::DataBagItem.load(data_bag, id).raw_data
|
38
38
|
end
|
39
39
|
|
40
|
+
def self.get_encrypted_data_bag_item(id, data_bag = :apps, secret = nil)
|
41
|
+
Chef::EncryptedDataBagItem.load(data_bag, id, secret).to_hash
|
42
|
+
end
|
43
|
+
|
40
44
|
# Load into Capistrano
|
41
45
|
def self.load_into(configuration)
|
42
46
|
self.configure_chef
|
43
47
|
configuration.set :capistrano_chef, self
|
44
48
|
configuration.load do
|
45
49
|
def chef_role(name, query = '*:*', options = {})
|
50
|
+
options = {:attribute => :ipaddress, :limit => 1000}.merge(options)
|
46
51
|
role name, *(capistrano_chef.search_chef_nodes(query, options.delete(:attribute), options.delete(:limit)) + [options])
|
47
52
|
end
|
48
53
|
|
@@ -52,6 +57,13 @@ module Capistrano::Chef
|
|
52
57
|
set k, v
|
53
58
|
end
|
54
59
|
end
|
60
|
+
|
61
|
+
def set_from_encrypted_data_bag(data_bag = :apps, secret = nil)
|
62
|
+
raise ':application must be set' if fetch(:application).nil?
|
63
|
+
capistrano_chef.get_encrypted_data_bag_item(application, data_bag, secret).each do |k, v|
|
64
|
+
set k, v
|
65
|
+
end
|
66
|
+
end
|
55
67
|
end
|
56
68
|
end
|
57
69
|
end
|
@@ -64,7 +64,6 @@ describe Capistrano::Chef do
|
|
64
64
|
expect { described_class.to be_a Module }
|
65
65
|
end
|
66
66
|
|
67
|
-
|
68
67
|
describe 'search_chef_nodes' do
|
69
68
|
before(:each) do
|
70
69
|
Chef::Knife.new.configure_chef
|
@@ -90,7 +89,7 @@ describe Capistrano::Chef do
|
|
90
89
|
# use Proc for more deep, complex attributes search.
|
91
90
|
specify 'with Proc argument' do
|
92
91
|
search_proc = Proc.new do |n|
|
93
|
-
n["network"]["interfaces"]["eth1"]["addresses"].select{|address, data| data["family"] == "inet" }.
|
92
|
+
n["network"]["interfaces"]["eth1"]["addresses"].select{|address, data| data["family"] == "inet" }.to_a.first.first
|
94
93
|
end
|
95
94
|
Capistrano::Chef.search_chef_nodes('*:*', search_proc).should eql ['192.168.77.101']
|
96
95
|
end
|
@@ -121,13 +120,35 @@ describe Capistrano::Chef do
|
|
121
120
|
@configuration.fetch(:id).should === 'other_test'
|
122
121
|
end
|
123
122
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
123
|
+
describe '#chef_role' do
|
124
|
+
it 'add nodes to the role' do
|
125
|
+
Capistrano::Chef.stub!(:search_chef_nodes).and_return(['10.0.0.2'])
|
126
|
+
@search = mock('Chef::Search::Query')
|
127
|
+
@configuration.should respond_to :chef_role
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
@configuration.chef_role(:test)
|
130
|
+
@configuration.roles.should have_key :test
|
131
|
+
@configuration.roles[:test].to_a[0].host.should === '10.0.0.2'
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'defaults to calling search with :ipaddress as the attribute and 1000 as the limit when giving a query' do
|
135
|
+
query = "this is my chef query"
|
136
|
+
Capistrano::Chef.should_receive(:search_chef_nodes).with(query, :ipaddress, 1000).and_return(['10.0.0.2'])
|
137
|
+
@configuration.chef_role(:test, query)
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'allows you to specify the attribute used in the query' do
|
141
|
+
query = "this is my chef query"
|
142
|
+
attribute = :my_attr
|
143
|
+
Capistrano::Chef.should_receive(:search_chef_nodes).with(query, attribute, 1000).and_return(['10.0.0.2'])
|
144
|
+
@configuration.chef_role(:test, query, :attribute => attribute)
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'allows you to specify the limit used in the query' do
|
148
|
+
query = "this is my chef query"
|
149
|
+
limit = 55
|
150
|
+
Capistrano::Chef.should_receive(:search_chef_nodes).with(query, :ipaddress, limit).and_return(['10.0.0.2'])
|
151
|
+
@configuration.chef_role(:test, query, :limit => limit)
|
152
|
+
end
|
132
153
|
end
|
133
154
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-chef
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
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: 2012-
|
12
|
+
date: 2012-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.10.
|
37
|
+
version: 0.10.10
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.10.
|
45
|
+
version: 0.10.10
|
46
46
|
description: Allows capistrano to use Chef data for deployment
|
47
47
|
email:
|
48
48
|
- nlloyds@gmail.com
|
@@ -77,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
77
|
version: '0'
|
78
78
|
segments:
|
79
79
|
- 0
|
80
|
-
hash: -
|
80
|
+
hash: -2495257063042549359
|
81
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
82
|
none: false
|
83
83
|
requirements:
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
version: '0'
|
87
87
|
segments:
|
88
88
|
- 0
|
89
|
-
hash: -
|
89
|
+
hash: -2495257063042549359
|
90
90
|
requirements: []
|
91
91
|
rubyforge_project: capistrano-chef
|
92
92
|
rubygems_version: 1.8.24
|