chef-helpers 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +64 -12
- data/chef-helpers.gemspec +1 -0
- data/lib/chef-helpers/has_source.rb +2 -2
- data/lib/chef-helpers/node.rb +16 -4
- data/lib/chef-helpers/version.rb +1 -1
- metadata +19 -15
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MjNkNmNmOWZmMGEzN2UyNmJlMDE1ZWFlMTEzYmU0YTEzZmNkOTVhYw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NWI5MmQxZDRjNmQ0NTc1MjNlMmFmNGQzZDQ5OWE0MWFlZTVlYWQ1Zg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTVhY2M5MzBkMzFlNjUzM2MxYjFjYzM0ZjY4NzFiNGZiNjY2OTg1NGVlNjg5
|
10
|
+
MzRhMTg2MWNhY2JlMDI3NGE4NzUwY2MwYTRiNjJmYTk4MjRkODA4NTU4MDZj
|
11
|
+
NTY2NGYzYTNjNDMyZWIyMGFjNDg0NTZjZTk1MzI4Y2I5YWNlZTc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDRlMDhmMmQyOGViNzgzZmRhM2JmODUwZjc0OGE0ZWI5YjU2YmU5MzA5MTBk
|
14
|
+
NDg1YjhhYjc0NjhlZDA5MmM2MTJjMzZmOWM5M2ZjMmI2NGUyNDM2MDBhOTNh
|
15
|
+
OTVhYTYxZTU0YzAzZDRjNWIyMTAxZWYzM2Y0ODFiY2NhNzczZmU=
|
data/README.md
CHANGED
@@ -4,26 +4,78 @@ This gem includes miscellaneous add-on helper methods for Opscode Chef.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
To use helper methods in your Chef recipes,
|
8
|
-
|
7
|
+
To use helper methods in your Chef recipes, use following code in your
|
8
|
+
recipe:
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
```ruby
|
11
|
+
chef_gem 'chef-helpers'
|
12
|
+
require 'chef-helpers'
|
13
|
+
```
|
12
14
|
|
13
|
-
|
15
|
+
To use the helpers locally in `knife exec` scripts or Knife plugins,
|
16
|
+
just add the `chef-helpers` gem to your dependencies and `require 'chef-helpers'`.
|
14
17
|
|
15
|
-
|
18
|
+
## Usage
|
16
19
|
|
17
|
-
|
20
|
+
Detailed documentation of the helper methods can be seen at
|
21
|
+
http://rdoc.info/github/3ofcoins/chef-helpers/
|
18
22
|
|
19
|
-
|
23
|
+
### Finding existing templates and cookbook files
|
20
24
|
|
21
|
-
|
25
|
+
The recipe DSL is extended with `ChefHelpers::HasSource` module that
|
26
|
+
provides methods for checking which templates and cookbook files exist
|
27
|
+
on the Chef server. Detailed docs are available at
|
28
|
+
http://rdoc.info/github/3ofcoins/chef-helpers/ChefHelpers/HasSource
|
22
29
|
|
23
|
-
|
30
|
+
### Chef::Node#allies
|
24
31
|
|
25
|
-
|
26
|
-
|
32
|
+
The `node.allies` method returns an array of node's *allies*. These
|
33
|
+
are: all nodes in the same environment (if the environment is not
|
34
|
+
`_default`), plus nodes specified by `allies` attribute. The `allies`
|
35
|
+
attribute - if set - should be an array of node names or node search
|
36
|
+
queries; the named nodes and search results will be added to node's
|
37
|
+
allies.
|
38
|
+
|
39
|
+
This is mostly useful when defining firewall or other access rules, to
|
40
|
+
easily limit access to insides of a cluster plus a handful of friendly
|
41
|
+
machines.
|
42
|
+
|
43
|
+
### Chef::Node#ip_for
|
44
|
+
|
45
|
+
The `node.ip_for(other_node)` method decides, which IP address should
|
46
|
+
the node use to contact the other node, and returns this IP as a
|
47
|
+
string. It is particularly useful when your setup spans across cloud
|
48
|
+
availability zones or different providers. At the moment only EC2 and
|
49
|
+
nodes with public `ipaddress` are supported; suggestions are welcome.
|
50
|
+
|
51
|
+
If both nodes are on EC2 and in the same region, then other node's
|
52
|
+
`ec2.local_ipv4` attribute is used. Otherwise, if other node is a
|
53
|
+
cloud instance, its `cloud_public.ipv4` attribute is used. Otherwise,
|
54
|
+
other node's `ipaddress` is used.
|
55
|
+
|
56
|
+
### JSONPath access to attributes
|
57
|
+
|
58
|
+
The `Chef::Node` class is monkey-patched to allow easy deep access to
|
59
|
+
the attributes using the
|
60
|
+
[JSONPath](http://goessner.net/articles/JsonPath/) syntax:
|
61
|
+
|
62
|
+
```
|
63
|
+
chef > require 'chef-helpers'
|
64
|
+
=> true
|
65
|
+
chef > node['$..name']
|
66
|
+
=> ["portinari-2.local", "Java(TM) SE Runtime Environment", "Java HotSpot(TM) 64-Bit Server VM", "Darwin"]
|
67
|
+
chef > node['$.kernel.name']
|
68
|
+
=> ["Darwin"]
|
69
|
+
```
|
70
|
+
|
71
|
+
Regular access to attributes is preserved; JSONPath is used only when
|
72
|
+
the attribute name starts with `$` character, or if a `JSONPath`
|
73
|
+
instance is used for indexing.
|
74
|
+
|
75
|
+
The [jsonpath gem](https://github.com/joshbuddy/jsonpath) is used for
|
76
|
+
the implementation. While the original gem allows modification, it's
|
77
|
+
not straightforward to achieve with Chef's attributes, so only reading
|
78
|
+
attributes with JSONPath is supported.
|
27
79
|
|
28
80
|
## Contributing
|
29
81
|
|
data/chef-helpers.gemspec
CHANGED
data/lib/chef-helpers/node.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'chef/node'
|
2
|
+
require 'jsonpath'
|
2
3
|
|
3
4
|
class Chef::Node
|
4
5
|
|
@@ -7,14 +8,14 @@ class Chef::Node
|
|
7
8
|
# attribute. The `allies` attribute - if set - should be an array of
|
8
9
|
# node names or node search queries; the named nodes and search
|
9
10
|
# results will be added to node's allies.
|
10
|
-
#
|
11
|
+
#
|
11
12
|
# This is mostly useful when defining firewall or other access
|
12
13
|
# rules, to easily limit access to insides of a cluster plus a
|
13
14
|
# handful of friendly machines.
|
14
15
|
#
|
15
16
|
# @return [Array<Chef::Node>] Array of node's "allies".
|
16
17
|
def allies
|
17
|
-
@allies ||=
|
18
|
+
@allies ||=
|
18
19
|
begin
|
19
20
|
rv = []
|
20
21
|
q = Chef::Search::Query.new
|
@@ -30,12 +31,12 @@ class Chef::Node
|
|
30
31
|
end
|
31
32
|
|
32
33
|
# Find out, which IP should be used to contact with other node.
|
33
|
-
#
|
34
|
+
#
|
34
35
|
# If both nodes are on EC2 and in the same region, then other node's
|
35
36
|
# `ec2.local_ipv4` attribute is used. Otherwise, if other node is a
|
36
37
|
# cloud instance, its `cloud_public.ipv4` attribute is
|
37
38
|
# used. Otherwise, other node's `ipaddress` is used.
|
38
|
-
#
|
39
|
+
#
|
39
40
|
# @note This method may return wrong IP with non-EC2 cloud
|
40
41
|
# providers, and can use some tweaking for such cases.
|
41
42
|
# @param [Chef::Node] other_node Node, whose IP we need to know
|
@@ -51,4 +52,15 @@ class Chef::Node
|
|
51
52
|
other_node['ipaddress']
|
52
53
|
end
|
53
54
|
end
|
55
|
+
|
56
|
+
# jsonpath access to node attributes
|
57
|
+
def brackets_with_jsonpath(key)
|
58
|
+
case key
|
59
|
+
when JsonPath then key.on(self.to_hash)
|
60
|
+
when /^\$/ then JsonPath.on(self.to_hash, key)
|
61
|
+
else self.brackets_without_jsonpath(key)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
alias_method :brackets_without_jsonpath, :[]
|
65
|
+
alias_method :[], :brackets_with_jsonpath
|
54
66
|
end
|
data/lib/chef-helpers/version.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Maciej Pasternacki
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-07-21 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: chef
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,20 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jsonpath
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
37
|
requirements:
|
27
38
|
- - ! '>='
|
28
39
|
- !ruby/object:Gem::Version
|
@@ -47,33 +58,26 @@ files:
|
|
47
58
|
- lib/chef-helpers/version.rb
|
48
59
|
homepage: https://github.com/3ofcoins/chef-helpers/
|
49
60
|
licenses: []
|
61
|
+
metadata: {}
|
50
62
|
post_install_message:
|
51
63
|
rdoc_options: []
|
52
64
|
require_paths:
|
53
65
|
- lib
|
54
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
67
|
requirements:
|
57
68
|
- - ! '>='
|
58
69
|
- !ruby/object:Gem::Version
|
59
70
|
version: '0'
|
60
|
-
segments:
|
61
|
-
- 0
|
62
|
-
hash: 2272563809326156327
|
63
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
72
|
requirements:
|
66
73
|
- - ! '>='
|
67
74
|
- !ruby/object:Gem::Version
|
68
75
|
version: '0'
|
69
|
-
segments:
|
70
|
-
- 0
|
71
|
-
hash: 2272563809326156327
|
72
76
|
requirements: []
|
73
77
|
rubyforge_project:
|
74
|
-
rubygems_version:
|
78
|
+
rubygems_version: 2.0.5
|
75
79
|
signing_key:
|
76
|
-
specification_version:
|
80
|
+
specification_version: 4
|
77
81
|
summary: Helper methods for Opscode Chef
|
78
82
|
test_files: []
|
79
83
|
has_rdoc:
|