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 CHANGED
@@ -2,8 +2,31 @@
2
2
  Chef\_Solo\_Nodes
3
3
  ===============
4
4
 
5
- Provides two functions: Chef\_Solo\_Nodes(), Chef\_Solo\_IPs()
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() # ===> [ Hash, Hash ]
44
+ Chef_Solo_Nodes() # ===> [ Hash, Hash ]
19
45
  Chef_Solo_Nodes('role_name') # ===> [ Hash, Hash ]
20
- Chef_Solo_IPs('db') # ===> [ String, String ]
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, *Chef_Solo_IPs('db')
61
+ role :db, *Chef_Solo_IPs('db')
28
62
 
29
- Usage: CAP\_IP
30
- --------------------
63
+ Equivalent to:
31
64
 
32
- $ CAP_IP file_name
33
- 127.0.0.1
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
- $ CAP_IP file_with_port
37
- 127.0.0.1:2222
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
- $ CAP_IP file_with_user_and_port
40
- vagrant@127.0.0.1:2222
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
- The user is excluded in the final print out, unlike with CAP\_IP.
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
- $ IP file_with_user_and_port
107
+ 127.0.0.1
48
108
  127.0.0.1:2222
49
- # Read from nodes/file_with_user_and_port.json
50
-
51
- $ IP file_with_no_port
52
- 127.0.0.1
109
+ user@127.0.0.1:2222
53
110
 
54
- Usage: SSH
111
+ Usage: IP --no-user
55
112
  --------------------
113
+ Removes the **user@** part of the address:
56
114
 
57
- $ SSH file_name
115
+ $ IP --no-user file_name
58
116
  127.0.0.1
59
- # Read from nodes/file_name.json
60
117
 
61
- $ SSH file_with_specified_user_or_login
62
- vagrant@127.0.0.1
118
+ Usage: SSH
119
+ --------------------
63
120
 
64
- $ SSH file_with_specified_port
65
- -p 2222 vagrant@127.0.0.1
121
+ $ SSH file_name
122
+ # Parses "nodes/file_name.json"
66
123
 
67
- $ ssh $( SSH vagrant )
68
- ssh -p 2222 vagrant@127.0.0.1
124
+ Depending on whether the attributes exist, the results could take
125
+ any form of the following:
69
126
 
70
- # Using knife-solo: https://github.com/matschaffer/knife-solo
71
- $ knife prepare $( SSH file_name )
72
- knife prepare -p 2222 vagrant@localhost
127
+ 127.0.0.1
128
+ user@127.0.0.1
129
+ -p 2222 user@127.0.0.1
73
130
 
74
- Implementation
75
- --------------
131
+ **Note:** SSH does not take any other options/arguments except for the file name.
76
132
 
77
- It's easier to understand if you see the code.
78
- [It's just one page long.](https://github.com/da99/Chef_Solo_Nodes/blob/master/lib/Chef_Solo_Nodes.rb)
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
- unless n
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
@@ -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
-
@@ -1,3 +1,3 @@
1
1
  class Chef_Solo_Nodes
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.1"
3
3
  end
data/spec/tests/IP.rb CHANGED
@@ -20,12 +20,29 @@ describe "IP" do
20
20
  }
21
21
  end
22
22
 
23
- it "does not include user if specified" do
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
@@ -32,7 +32,7 @@ describe "SSH" do
32
32
  }
33
33
  end
34
34
 
35
- it "adds user if \"user\" is specified" do
35
+ it "adds user if \"login\" is specified" do
36
36
  chdir {
37
37
  `SSH "with_login"`.should == "log_RjD2@localhost"
38
38
  }
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.3.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-19 00:00:00.000000000 Z
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
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require "Chef_Solo_Nodes"
3
-
4
- n = Chef_Solo_IPs(Dir.glob("nodes/#{ARGV.first}.json")).first
5
-
6
- unless n
7
- print 'xx.xx.xx.xx'
8
- exit 1
9
- end
10
-
11
- print n
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
-