spiceweasel 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  Description
2
2
  ===========
3
- Spiceweasel is a command-line tool for batch loading Chef infrastructure. It provides a simple syntax for describing and deploying infrastructure in order with the Chef command-line tool `knife`.
3
+ Spiceweasel is a command-line tool for batch loading Chef infrastructure. It provides a simple syntax in either JSON or YAML for describing and deploying infrastructure in order with the Chef command-line tool `knife`.
4
4
 
5
5
  CHANGELOG.md covers current, previous and future development milestones and contains the features backlog.
6
6
 
7
7
  Requirements
8
8
  ============
9
- Spiceweasel currently depends on `knife` to run commands for it.
9
+ Spiceweasel currently depends on `knife` to run commands for it. Infrastructure files must either end in .json or .yml to be processed.
10
10
 
11
11
  Written with Chef 0.9.12 and 0.9.14 and supports cookbooks, recipes, roles, data bags and nodes. Support for environments will be added with the Chef 0.10 release.
12
12
 
@@ -16,7 +16,66 @@ Tested with Ubuntu 10.04 and 10.10 and Chef 0.9.12 and 0.9.14.
16
16
 
17
17
  File Syntax
18
18
  ===========
19
- The syntax for the spiceweasel file is a simple YAML format of Chef primitives describing what is to be instantiated.
19
+ The syntax for the spiceweasel file may be either JSON or YAML format of Chef primitives describing what is to be instantiated. Below or 2 examples describing the same infrastructure.
20
+
21
+ JSON
22
+ ----
23
+ From the `example.json`:
24
+
25
+ {
26
+ "cookbooks":
27
+ [
28
+ {"apache2":[]},
29
+ {"apt":
30
+ [
31
+ "1.1.0"
32
+ ]
33
+ },
34
+ {"mysql":[]}
35
+ ],
36
+ "roles":
37
+ [
38
+ {"base":[]},
39
+ {"monitoring":[]},
40
+ {"webserver":[]}
41
+ ],
42
+ "data bags":
43
+ [
44
+ {"users":
45
+ [
46
+ "alice",
47
+ "bob",
48
+ "chuck"
49
+ ]
50
+ },
51
+ {"data":[]}
52
+ ],
53
+ "nodes":
54
+ [
55
+ {"serverA":
56
+ [
57
+ "role[base]",
58
+ "-i ~/.ssh/mray.pem -x user --sudo -d ubuntu10.04-gems"
59
+ ]
60
+ },
61
+ {"ec2 5":
62
+ [
63
+ "role[webserver] recipe[mysql::client]",
64
+ "-S mray -I ~/.ssh/mray.pem -x ubuntu -G default -i ami-a403f7cd -f m1.small"
65
+ ]
66
+ },
67
+ {"rackspace 3":
68
+ [
69
+ "recipe[mysql] role[monitoring]",
70
+ "--image 49 --flavor 2"
71
+ ]
72
+ }
73
+ ]
74
+ }
75
+
76
+ YAML
77
+ ----
78
+ From the `example.yml`:
20
79
 
21
80
  cookbooks:
22
81
  - apache2:
@@ -49,7 +108,7 @@ The syntax for the spiceweasel file is a simple YAML format of Chef primitives d
49
108
 
50
109
  Cookbooks
51
110
  ---------
52
- The `cookbooks` section of the YAML file currently supports `knife cookbook upload FOO` where `FOO` is the name of the cookbook in the `cookbooks` directory. If a version is passed, it is validated against an existing cookbook `metadata.rb` and if none is found, the missing cookbook is downloaded. The YAML snippet
111
+ The `cookbooks` section of the JSON or YAML file currently supports `knife cookbook upload FOO` where `FOO` is the name of the cookbook in the `cookbooks` directory. If a version is passed, it is validated against an existing cookbook `metadata.rb` and if none is found, the missing cookbook is downloaded. The YAML snippet
53
112
 
54
113
  cookbooks:
55
114
  - apache2:
@@ -66,7 +125,7 @@ produces the knife commands
66
125
 
67
126
  Roles
68
127
  -----
69
- The `roles` section of the YAML file currently supports `knife role from file FOO` where `FOO` is the name of the role file ending in `.rb` in the `roles` directory. The YAML snippet
128
+ The `roles` section of the JSON or YAML file currently supports `knife role from file FOO` where `FOO` is the name of the role file ending in `.rb` in the `roles` directory. The YAML snippet
70
129
 
71
130
  roles:
72
131
  - base:
@@ -81,7 +140,7 @@ produces the knife commands
81
140
 
82
141
  Data Bags
83
142
  ---------
84
- The `data bags` section of the YAML file currently creates the data bags listed with `knife data bag create FOO` where `FOO` is the name of the data bag. Individual items may be added to the data bag as part of a YAML sequence, the assumption is made that they `.json` files and in the `data_bags` directory. The YAML snippet
143
+ The `data bags` section of the JSON or YAML file currently creates the data bags listed with `knife data bag create FOO` where `FOO` is the name of the data bag. Individual items may be added to the data bag as part of a JSON or YAML sequence, the assumption is made that they `.json` files and in the `data_bags` directory. The YAML snippet
85
144
 
86
145
  data bags:
87
146
  - users:
@@ -100,7 +159,7 @@ produces the knife commands
100
159
 
101
160
  Nodes
102
161
  -----
103
- The `nodes` section of the YAML file bootstraps a node for each entry where the entry is a hostname or provider and count. Each node requires 2 items after it in a YAML sequence. The first item is the run_list and the second the CLI options used. Validation is performed on the run_list components to ensure that only recipes and roles listed in the YAML file are used. A shortcut syntax for bulk-creating nodes with various providers where the line starts with the provider and ends with the number of nodes to be provisioned. The YAML snippet
162
+ The `nodes` section of the JSON or YAML file bootstraps a node for each entry where the entry is a hostname or provider and count. Each node requires 2 items after it in a sequence. The first item is the run_list and the second the CLI options used. Validation is performed on the run_list components to ensure that only recipes and roles listed in the file are used. A shortcut syntax for bulk-creating nodes with various providers where the line starts with the provider and ends with the number of nodes to be provisioned. The YAML snippet
104
163
 
105
164
  nodes:
106
165
  - serverA:
@@ -129,9 +188,13 @@ Usage
129
188
  =====
130
189
  To run a spiceweasel file, run the following from you Chef repository directory:
131
190
 
191
+ spiceweasel path/to/infrastructure.json
192
+
193
+ or
194
+
132
195
  spiceweasel path/to/infrastructure.yml
133
196
 
134
- This will generate the knife commands to build the described infrastructure.
197
+ This will generate the knife commands to build the described infrastructure. Infrastructure files must end in either `.json` or `.yml`.
135
198
 
136
199
  --dryrun
137
200
  --------
@@ -139,7 +202,7 @@ This is the default action, printing the knife commands to be run without execut
139
202
 
140
203
  -d/--delete
141
204
  -----------
142
- The delete command will generate the knife commands to delete the infrastructure described in the YAML file. This includes each cookbook, role, data bag, environment and node listed. Currently all nodes from the system are deleted with `knife node bulk_delete`, specific-node support will be added in a future release.
205
+ The delete command will generate the knife commands to delete the infrastructure described in the file. This includes each cookbook, role, data bag, environment and node listed. Currently all nodes from the system are deleted with `knife node bulk_delete`, specific-node support will be added in a future release.
143
206
 
144
207
  -h/--help
145
208
  ---------
@@ -147,7 +210,7 @@ Print the currently-supported usage options for spiceweasel.
147
210
 
148
211
  -r/--rebuild
149
212
  ---------
150
- The rebuild command will generate the knife commands to delete and recreate the infrastructure described in the YAML file. This includes each cookbook, role, data bag, environment and node listed. Currently all nodes from the system are deleted with `knife node bulk_delete`, specific-node support will be added in a future release.
213
+ The rebuild command will generate the knife commands to delete and recreate the infrastructure described in the file. This includes each cookbook, role, data bag, environment and node listed. Currently all nodes from the system are deleted with `knife node bulk_delete`, specific-node support will be added in a future release.
151
214
 
152
215
  -v/--version
153
216
  ------------
data/bin/spiceweasel CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'json'
3
4
  require 'mixlib/cli'
4
- require 'yaml'
5
5
  require 'spiceweasel/version'
6
+ require 'yaml'
6
7
 
7
8
  #ensure that the run_list contents are present in either the cookbooks or roles
8
9
  def validate_run_list(run_list, cookbooks, roles)
@@ -81,9 +82,17 @@ rescue OptionParser::InvalidOption => e
81
82
  end
82
83
 
83
84
  begin
84
- yml = YAML.load_file ARGV.last
85
+ file = ARGV.last
86
+ if (file.end_with?(".yml"))
87
+ input = YAML.load_file ARGV.last
88
+ elsif (file.end_with?(".json"))
89
+ input = JSON.parse(File.read(ARGV.last))
90
+ else
91
+ raise "Unknown file type, please use a file ending with either '.json' or '.yml'."
92
+ exit(-1)
93
+ end
85
94
  rescue Exception
86
- STDERR.puts "No infrastructure YAML file provided."
95
+ STDERR.puts "No infrastructure .json or .yml file provided."
87
96
  puts cli.opt_parser.to_s
88
97
  exit(-1)
89
98
  end
@@ -92,7 +101,7 @@ create = String.new()
92
101
  delete = String.new()
93
102
 
94
103
  #cookbooks
95
- cookbooks = yml['cookbooks'] || []
104
+ cookbooks = input['cookbooks'] || []
96
105
  cookbook_list = []
97
106
  cookbooks.each do |cookbook|
98
107
  cb = cookbook.keys.first
@@ -119,7 +128,7 @@ cookbooks.each do |cookbook|
119
128
  end
120
129
 
121
130
  #roles
122
- roles = yml['roles'] || []
131
+ roles = input['roles'] || []
123
132
  role_list = []
124
133
  roles.each do |role|
125
134
  delete += "knife role delete #{role.keys[0]} -y\n"
@@ -129,7 +138,7 @@ roles.each do |role|
129
138
  end
130
139
 
131
140
  #data bags
132
- bags = yml['data bags'] || []
141
+ bags = input['data bags'] || []
133
142
  bags.each do |bag|
134
143
  delete += "knife data bag delete #{bag.keys[0]} -y\n"
135
144
  create += "knife data bag create #{bag.keys[0]}\n"
@@ -139,7 +148,7 @@ bags.each do |bag|
139
148
  end
140
149
  end
141
150
 
142
- nodes = yml['nodes'] || []
151
+ nodes = input['nodes'] || []
143
152
  #currently use bulk_delete for deleting, add provider support real soon
144
153
  delete += "knife node bulk_delete .* -y\n"
145
154
  nodes.each do |node|
data/example.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "cookbooks":
3
+ [
4
+ {"apache2":[]},
5
+ {"apt":
6
+ [
7
+ "1.1.0"
8
+ ]
9
+ },
10
+ {"mysql":[]}
11
+ ],
12
+ "roles":
13
+ [
14
+ {"base":[]},
15
+ {"monitoring":[]},
16
+ {"webserver":[]}
17
+ ],
18
+ "data bags":
19
+ [
20
+ {"users":
21
+ [
22
+ "alice",
23
+ "bob",
24
+ "chuck"
25
+ ]
26
+ },
27
+ {"data":[]}
28
+ ],
29
+ "nodes":
30
+ [
31
+ {"serverA":
32
+ [
33
+ "role[base]",
34
+ "-i ~/.ssh/mray.pem -x user --sudo -d ubuntu10.04-gems"
35
+ ]
36
+ },
37
+ {"ec2 5":
38
+ [
39
+ "role[webserver] recipe[mysql::client]",
40
+ "-S mray -I ~/.ssh/mray.pem -x ubuntu -G default -i ami-a403f7cd -f m1.small"
41
+ ]
42
+ },
43
+ {"rackspace 3":
44
+ [
45
+ "recipe[mysql] role[monitoring]",
46
+ "--image 49 --flavor 2"
47
+ ]
48
+ }
49
+ ]
50
+ }
@@ -1,3 +1,3 @@
1
1
  module Spiceweasel
2
- VERSION = "0.4"
2
+ VERSION = "0.5"
3
3
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spiceweasel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
9
- version: "0.4"
8
+ - 5
9
+ version: "0.5"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Matt Ray
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-11 00:00:00 -06:00
17
+ date: 2011-03-14 00:00:00 -10:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -34,6 +34,7 @@ files:
34
34
  - README.md
35
35
  - Rakefile
36
36
  - bin/spiceweasel
37
+ - example.json
37
38
  - example.yml
38
39
  - lib/spiceweasel.rb
39
40
  - lib/spiceweasel/version.rb