Chef_Solo_Nodes 0.3.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +95 -35
- data/bin/IP +8 -4
- data/lib/Chef_Solo_Nodes.rb +1 -2
- data/lib/Chef_Solo_Nodes/version.rb +1 -1
- data/spec/tests/IP.rb +20 -3
- data/spec/tests/SSH.rb +1 -1
- metadata +2 -5
- data/bin/CAP_IP +0 -11
- data/spec/tests/CAP_IP.rb +0 -31
data/README.md
CHANGED
@@ -2,8 +2,31 @@
|
|
2
2
|
Chef\_Solo\_Nodes
|
3
3
|
===============
|
4
4
|
|
5
|
-
|
5
|
+
Parse files from "nodes/\*.json" to help you integrate your Chef-Solo
|
6
|
+
nodes with Capistrano, Knife-Solo, SSH, etc.
|
6
7
|
|
8
|
+
The .json file can optionally define any of the following attributes:
|
9
|
+
|
10
|
+
* "ipaddress" - If not defined, file name used: node/[FILE\_NAME].json
|
11
|
+
* "user" || "login"
|
12
|
+
* "port"
|
13
|
+
|
14
|
+
Example: node/Machine\_Name.json
|
15
|
+
--------------------------------
|
16
|
+
|
17
|
+
{
|
18
|
+
"ipaddress": "localhost",
|
19
|
+
"port": 2222,
|
20
|
+
"user": "vagrant",
|
21
|
+
"roles": ["dev"],
|
22
|
+
"run_list": [ "recipe[...]", "recipe[....]"]
|
23
|
+
}
|
24
|
+
|
25
|
+
Implementation
|
26
|
+
--------------
|
27
|
+
|
28
|
+
Most of the action is in
|
29
|
+
[less than 100 lines of code.](https://github.com/da99/Chef_Solo_Nodes/blob/master/lib/Chef_Solo_Nodes.rb)
|
7
30
|
|
8
31
|
Installation
|
9
32
|
-----------
|
@@ -13,68 +36,105 @@ Installation
|
|
13
36
|
Usage: Ruby
|
14
37
|
----------
|
15
38
|
|
39
|
+
Provides two functions: Chef\_Solo\_Nodes(), Chef\_Solo\_IPs().
|
40
|
+
You can pass them an optional role name to filter the nodes.
|
41
|
+
|
16
42
|
require "Chef_Solo_Nodes"
|
17
43
|
|
18
|
-
Chef_Solo_Nodes()
|
44
|
+
Chef_Solo_Nodes() # ===> [ Hash, Hash ]
|
19
45
|
Chef_Solo_Nodes('role_name') # ===> [ Hash, Hash ]
|
20
|
-
Chef_Solo_IPs('db')
|
46
|
+
Chef_Solo_IPs('db') # ===> [ "hostname", "user@hostname:port" ]
|
47
|
+
|
48
|
+
If the argument is an Array, it will treat each element as a
|
49
|
+
file path to a JSON file:
|
50
|
+
|
51
|
+
paths = [ "node/FILE_1.json", "node/FILE_2.json" ]
|
52
|
+
Chef_Solo_Nodes paths
|
53
|
+
Chef_Solo_IPs paths
|
54
|
+
|
21
55
|
|
22
56
|
Usage: Capistrano
|
23
57
|
----------------
|
24
58
|
|
25
59
|
require "Chef_Solo_Nodes"
|
26
60
|
role :app, *Chef_Solo_IPs('app')
|
27
|
-
role :db,
|
61
|
+
role :db, *Chef_Solo_IPs('db')
|
28
62
|
|
29
|
-
|
30
|
-
--------------------
|
63
|
+
Equivalent to:
|
31
64
|
|
32
|
-
|
33
|
-
|
34
|
-
# Read from nodes/file_name.json
|
65
|
+
role :app, "user@host:port", "192.0.0.42"
|
66
|
+
role :db, "super.secret.base"
|
35
67
|
|
36
|
-
|
37
|
-
|
68
|
+
Usage: Shell
|
69
|
+
------------
|
70
|
+
|
71
|
+
Provides 2 executables: IP and SSH
|
72
|
+
|
73
|
+
All they do is print out to standard output. They are meant to
|
74
|
+
generate arguments for other programs:
|
75
|
+
|
76
|
+
$ ping -c 3 $( IP --no-user file_name )
|
77
|
+
ping -c 3 my.ip.address
|
78
|
+
|
79
|
+
$ ssh $( SSH file_name )
|
80
|
+
ssh -p 2222 user@ip.address
|
38
81
|
|
39
|
-
$
|
40
|
-
|
82
|
+
$ knife prepare $( SSH file_name )
|
83
|
+
knife prepare -p 4567 user@ip.address
|
84
|
+
|
85
|
+
**Tip:** the last example above uses
|
86
|
+
[knife-solo](https://github.com/matschaffer/knife-solo).
|
87
|
+
|
88
|
+
Usage: Errors for IP, SSH
|
89
|
+
-------------------------
|
90
|
+
|
91
|
+
If the file name does not exist:
|
92
|
+
|
93
|
+
$ IP missing_file
|
94
|
+
$ SSH missing_file
|
95
|
+
xx.xx.xx.xx
|
96
|
+
# exit status = 1
|
41
97
|
|
42
98
|
Usage: IP
|
43
99
|
--------------------
|
44
100
|
|
45
|
-
|
101
|
+
$ IP file_name
|
102
|
+
# Parses "nodes/file_name.json"
|
103
|
+
|
104
|
+
Depending on whether the attributes exist, the results could take
|
105
|
+
any form of the following:
|
46
106
|
|
47
|
-
|
107
|
+
127.0.0.1
|
48
108
|
127.0.0.1:2222
|
49
|
-
|
50
|
-
|
51
|
-
$ IP file_with_no_port
|
52
|
-
127.0.0.1
|
109
|
+
user@127.0.0.1:2222
|
53
110
|
|
54
|
-
Usage:
|
111
|
+
Usage: IP --no-user
|
55
112
|
--------------------
|
113
|
+
Removes the **user@** part of the address:
|
56
114
|
|
57
|
-
$
|
115
|
+
$ IP --no-user file_name
|
58
116
|
127.0.0.1
|
59
|
-
# Read from nodes/file_name.json
|
60
117
|
|
61
|
-
|
62
|
-
|
118
|
+
Usage: SSH
|
119
|
+
--------------------
|
63
120
|
|
64
|
-
$ SSH
|
65
|
-
|
121
|
+
$ SSH file_name
|
122
|
+
# Parses "nodes/file_name.json"
|
66
123
|
|
67
|
-
|
68
|
-
|
124
|
+
Depending on whether the attributes exist, the results could take
|
125
|
+
any form of the following:
|
69
126
|
|
70
|
-
|
71
|
-
|
72
|
-
|
127
|
+
127.0.0.1
|
128
|
+
user@127.0.0.1
|
129
|
+
-p 2222 user@127.0.0.1
|
73
130
|
|
74
|
-
|
75
|
-
--------------
|
131
|
+
**Note:** SSH does not take any other options/arguments except for the file name.
|
76
132
|
|
77
|
-
|
78
|
-
|
133
|
+
Run Tests
|
134
|
+
---------
|
79
135
|
|
136
|
+
git clone git@github.com:da99/Chef_Solo_Nodes.git
|
137
|
+
cd Chef_Solo_Nodes
|
138
|
+
bundle update
|
139
|
+
bundle exec bacon spec/main.rb
|
80
140
|
|
data/bin/IP
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require "Chef_Solo_Nodes"
|
3
|
+
require "trollop"
|
4
|
+
|
5
|
+
opts = Trollop::options do
|
6
|
+
opt :no_user, "Avoid printing any user/login value", :default=>false
|
7
|
+
end
|
3
8
|
|
4
9
|
n = Chef_Solo_IPs(Dir.glob("nodes/#{ARGV.first}.json")).first
|
5
10
|
|
6
|
-
|
11
|
+
if !n
|
7
12
|
print 'xx.xx.xx.xx'
|
8
13
|
exit 1
|
9
14
|
end
|
10
15
|
|
11
16
|
uri = URI.parse("ssh://#{n}")
|
12
17
|
|
18
|
+
print "#{uri.user}@" if uri.user && !opts[:no_user]
|
13
19
|
print "#{uri.host}"
|
14
|
-
if uri.port
|
15
|
-
print ":#{uri.port}"
|
16
|
-
end
|
20
|
+
print ":#{uri.port}" if uri.port
|
data/lib/Chef_Solo_Nodes.rb
CHANGED
@@ -15,7 +15,7 @@ def Chef_Solo_Nodes role_or_paths = '*'
|
|
15
15
|
|
16
16
|
if role_or_paths.is_a?(Array)
|
17
17
|
role = '*'
|
18
|
-
files = role_or_paths
|
18
|
+
files = role_or_paths.map { |path| File.expand_path(path) }
|
19
19
|
else
|
20
20
|
role = role_or_paths.to_s
|
21
21
|
files = Dir.glob("nodes/*.json")
|
@@ -51,4 +51,3 @@ def Chef_Solo_IPs *args
|
|
51
51
|
}
|
52
52
|
end
|
53
53
|
|
54
|
-
|
data/spec/tests/IP.rb
CHANGED
@@ -20,12 +20,29 @@ describe "IP" do
|
|
20
20
|
}
|
21
21
|
end
|
22
22
|
|
23
|
-
it "
|
23
|
+
it "includes user if specified" do
|
24
24
|
chdir {
|
25
|
-
`bundle exec IP "with_user"`.should == "localhost"
|
25
|
+
`bundle exec IP "with_user"`.should == "RjD2@localhost"
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "includes login if specified" do
|
30
|
+
chdir {
|
31
|
+
`bundle exec IP "with_login"`.should == "log_RjD2@localhost"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
it "excludes user if --no-user is specified" do
|
36
|
+
chdir {
|
37
|
+
`bundle exec IP --no-user "with_user"`.should == "localhost"
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
it "excludes login if --no-user is specified" do
|
42
|
+
chdir {
|
43
|
+
`bundle exec IP --no-user "with_login"`.should == "localhost"
|
26
44
|
}
|
27
45
|
end
|
28
|
-
|
29
46
|
|
30
47
|
end # === IP
|
31
48
|
|
data/spec/tests/SSH.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Chef_Solo_Nodes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
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-03-
|
12
|
+
date: 2012-03-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bacon
|
@@ -96,7 +96,6 @@ description: ! "\n Use with Chef-Solo. Grabs node info as array of Hashes or
|
|
96
96
|
email:
|
97
97
|
- i-hate-spam-45671204@mailinator.com
|
98
98
|
executables:
|
99
|
-
- CAP_IP
|
100
99
|
- IP
|
101
100
|
- SSH
|
102
101
|
extensions: []
|
@@ -108,7 +107,6 @@ files:
|
|
108
107
|
- LICENSE
|
109
108
|
- README.md
|
110
109
|
- Rakefile
|
111
|
-
- bin/CAP_IP
|
112
110
|
- bin/IP
|
113
111
|
- bin/SSH
|
114
112
|
- lib/Chef_Solo_Nodes.rb
|
@@ -124,7 +122,6 @@ files:
|
|
124
122
|
- spec/data/nodes/with_user.json
|
125
123
|
- spec/helper.rb
|
126
124
|
- spec/main.rb
|
127
|
-
- spec/tests/CAP_IP.rb
|
128
125
|
- spec/tests/Chef_Solo_IPs.rb
|
129
126
|
- spec/tests/Chef_Solo_Nodes.rb
|
130
127
|
- spec/tests/IP.rb
|
data/bin/CAP_IP
DELETED
data/spec/tests/CAP_IP.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "CAP_IP" do
|
3
|
-
|
4
|
-
it "prints xx.xx.xx.xx if file is not found" do
|
5
|
-
chdir {
|
6
|
-
`CAP_IP not.found.json`.should == "xx.xx.xx.xx"
|
7
|
-
}
|
8
|
-
end
|
9
|
-
|
10
|
-
it "exists with 1 if not found" do
|
11
|
-
chdir {
|
12
|
-
`CAP_IP not.found.json`
|
13
|
-
$?.exitstatus.should == 1
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
|
-
it "returns only one result" do
|
18
|
-
chdir {
|
19
|
-
`bundle exec CAP_IP "*"`.should == "freemont"
|
20
|
-
}
|
21
|
-
end
|
22
|
-
|
23
|
-
it "includes user if specified" do
|
24
|
-
chdir {
|
25
|
-
`bundle exec CAP_IP "with_user"`.should == "RjD2@localhost"
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
end # === IP
|
31
|
-
|