rzo 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93c6d5a4116cc4e11c108ab19356d1e1ada72d32
4
- data.tar.gz: 12a9d2d9b7f138925a474170294a05d0481e32f9
3
+ metadata.gz: f2954e0711d95a790a603140732d64ad23aa31b4
4
+ data.tar.gz: e4240edc192d28ddc36cc95f7a07663b1a2aff9f
5
5
  SHA512:
6
- metadata.gz: ab032adafed7bca9cb0905718feb61ad77e058d7299635c5a29a013292bcb092d54cf69e8d2774b9f208a178e896f1c2e237fb9937e760d9cd5b8ba1065b2a78
7
- data.tar.gz: 40680c98c1034fd4c6fd91b1ca8bf680ba81f3489b55ba4ace6f4fde85c0052b16bc5dcd4546b12e04b560e667c28530af1213a59e78e9b59806c361d1e6dcf2
6
+ metadata.gz: 798d1d7b8934a933bf1799811b07a6e9621971777aeadf80fe114e46796153a810c6f1a88f9ce6ff129d1cf8a1407e7c8bc4d58afa542d4b64b5dc6fc64788ed
7
+ data.tar.gz: b85c666c757ca10feb5bc8bff846a1104ef0b264f295e7ad7d309b211a77cab3ee2b5c7de463ade2e544a6007b7346990bb24f178b53e239f5cc17f254c15965
@@ -19,9 +19,6 @@ Style/InverseMethods:
19
19
  Style/FrozenStringLiteralComment:
20
20
  Enabled: false
21
21
 
22
- Lint/UnneededDisable:
23
- Enabled: false
24
-
25
22
  Layout/MultilineOperationIndentation:
26
23
  Enabled: false
27
24
 
@@ -50,7 +47,10 @@ Style/Next:
50
47
  Style/NonNilCheck:
51
48
  Enabled: false
52
49
 
53
- Style/TrailingCommaInLiteral:
50
+ Style/TrailingCommaInArrayLiteral:
51
+ Enabled: false
52
+
53
+ Style/TrailingCommaInHashLiteral:
54
54
  Enabled: false
55
55
 
56
56
  Style/TrailingCommaInArguments:
@@ -6,8 +6,8 @@ notifications:
6
6
  email: false
7
7
 
8
8
  rvm:
9
- - 2.1.9
10
- - 2.4.1
9
+ - 2.4.4
10
+ - 2.5.1
11
11
 
12
12
  script:
13
13
  - 'bundle exec rake validate rubocop'
data/README.md CHANGED
@@ -4,14 +4,14 @@ Rizzo is a heavily customized Vagrant configuration and work flow with a
4
4
  role based focus. It is meant to make working with Vagrant easier and
5
5
  purpose built for layered Puppet control repositories.
6
6
 
7
- Rizzo loads a personal configuration file, `~/.rizzo.json` by default, which
8
- lists one or more control repositories. Rizzo then looks for and loads a
9
- `.rizzo.json` configuration file located at the root of the top level control
10
- repository. The top level control repository is the first listed in
7
+ Rizzo loads a personal configuration file, `~/.rizzo.yaml` by default, which
8
+ lists one or more control repositories. Rizzo then looks for and loads a
9
+ `.rizzo.yaml` configuration file located at the root of the top level control
10
+ repository. The top level control repository is the first listed in
11
11
  the array of control repositories in the personal configuration file.
12
12
 
13
13
  There should be at least one node for every role that is managed by a
14
- control repo. This information is stored in `.rizzo.json` under the
14
+ control repo. This information is stored in `.rizzo.yaml` under the
15
15
  control repo. This makes it apparent what roles are available and aids
16
16
  in functional testing.
17
17
 
@@ -29,7 +29,7 @@ Tested to work with ruby versions associated with Puppet, see
29
29
 
30
30
  # Installation
31
31
 
32
- Add the rizzo gem to your control repository `Gemfile`. For example, in
32
+ Add the rizzo gem to your control repository `Gemfile`. For example, in
33
33
  `puppetdata`:
34
34
 
35
35
  ```diff
@@ -61,7 +61,7 @@ bundle exec rizzo --help
61
61
  usage: rizzo [GLOBAL OPTIONS] SUBCOMMAND [ARGS]
62
62
  Sub Commands:
63
63
 
64
- config Print out the combined rizzo json config
64
+ config Print out the combined rizzo yaml config
65
65
  generate Initialize Vagrantfile in top control repo
66
66
 
67
67
  Global options: (Note, command line arguments supersede ENV vars in {}'s)
@@ -69,12 +69,12 @@ Global options: (Note, command line arguments supersede ENV vars in {}'s)
69
69
  -s, --syslog Log to syslog
70
70
  -v, --verbose Set log level to INFO
71
71
  -d, --debug Set log level to DEBUG
72
- -c, --config=<s> Rizzo config file {RZO_CONFIG} (default: ~/.rizzo.json)
72
+ -c, --config=<s> Rizzo config file {RZO_CONFIG} (default: ~/.rizzo.yaml)
73
73
  -e, --version Print version and exit
74
74
  -h, --help Show this message
75
75
  ```
76
76
 
77
- Once rizzo is installed, setup your configuration file, `~/.rizzo.json`, then
77
+ Once rizzo is installed, setup your configuration file, `~/.rizzo.yaml`, then
78
78
  use `bundle exec rizzo generate` to write the `Vagrantfile` in your control
79
79
  repo.
80
80
 
@@ -94,48 +94,40 @@ repo.
94
94
 
95
95
  # Setup
96
96
 
97
- ## `~/.rizzo.json`
97
+ ## `~/.rizzo.yaml`
98
98
 
99
- The personal configuration file is loaded first, from `~/.rizzo.json` by default.
99
+ The personal configuration file is loaded first, from `~/.rizzo.yaml` by default.
100
100
  The global `--config` option allows the end user to specific a different path to
101
101
  the personal configuration file.
102
102
 
103
103
  Using this example, change the paths to your git repos:
104
104
 
105
- ```json
106
- {
107
- "defaults": {
108
- "bootstrap_repo_path": "/Users/gh/git/bootstrap"
109
- },
110
- "control_repos": [
111
- "/Users/gh/git/puppet-control-myteam",
112
- "/Users/gh/git/puppetdata",
113
- "/Users/gh/git/puppet-modules"
114
- ],
115
- "puppetmaster": {
116
- "name": "infra-puppetca",
117
- "modulepath": [
118
- "./modules",
119
- "./puppetdata/modules",
120
- "./ghoneycutt/modules"
121
- ],
122
- "synced_folders": {
123
- "/repos/puppetdata": {
124
- "local": "/Users/gh/git/puppetdata",
125
- "owner": "root",
126
- "group": "root"
127
- },
128
- "/repos/ghoneycutt": {
129
- "local": "/Users/gh/git/puppet-modules",
130
- "owner": "root",
131
- "group": "root"
132
- }
133
- }
134
- }
135
- }
105
+ ```yaml
106
+ ---
107
+ defaults:
108
+ bootstrap_repo_path: "/Users/gh/git/bootstrap"
109
+ control_repos:
110
+ - "/Users/gh/git/puppet-control-myteam"
111
+ - "/Users/gh/git/puppetdata"
112
+ - "/Users/gh/git/puppet-modules"
113
+ puppetmaster:
114
+ name: "infra-puppetca"
115
+ modulepath:
116
+ - "./modules"
117
+ - "./puppetdata/modules"
118
+ - "./ghoneycutt/modules"
119
+ synced_folders:
120
+ /repos/puppetdata:
121
+ local: "/Users/gh/git/puppetdata"
122
+ owner: "root"
123
+ group: "root"
124
+ /repos/ghoneycutt:
125
+ local: "/Users/gh/git/puppet-modules"
126
+ owner: "root"
127
+ group: "root"
136
128
  ```
137
129
 
138
- Once you have a personal config file, `~/.rizzo.json`, change directories to
130
+ Once you have a personal config file, `~/.rizzo.yaml`, change directories to
139
131
  your top level control repository and generate your `Vagrantfile`:
140
132
 
141
133
  ```shell
@@ -171,15 +163,15 @@ VM, run `vagrant status NAME`.
171
163
  ### defaults
172
164
 
173
165
  The defaults hash is merged with each node entries hash. Put user
174
- specific entries in the personal configuration file at `~/.rizzo.json` and
175
- control repo specific entries in `${PATH_TO_CONTROL_REPO}/.rizzo.json`.
166
+ specific entries in the personal configuration file at `~/.rizzo.yaml` and
167
+ control repo specific entries in `${PATH_TO_CONTROL_REPO}/.rizzo.yaml`.
176
168
 
177
169
  ### control_repos
178
170
 
179
171
  The control_repos array is a list of control repos. Rizzo takes the
180
172
  approach that control repos are layered. The ordering should match your
181
173
  `puppetmaster['modulepath']` array. The first control repo with a
182
- `.rizzo.json` in it will have that Rizzo config used.
174
+ `.rizzo.yaml` in it will have that Rizzo config used.
183
175
 
184
176
  ### puppetmaster
185
177
 
@@ -207,52 +199,54 @@ local, which is the path on the host and owner and group which are the
207
199
  owner and group permissions the directory will be mounted with on the
208
200
  guest.
209
201
 
210
- ## `controlrepo/.rizzo.json`
211
-
212
- ```json
213
- {
214
- "defaults": {
215
- "bootstrap_script_path": "bootstrap_puppet4.sh",
216
- "bootstrap_script_args": "-l -f `hostname -f`",
217
- "bootstrap_guest_path": "/tmp/bootstrap",
218
- "boot_timeout": "500",
219
- "box": "centos7.box",
220
- "box_url": "https://vagrantboxes/centos7.box",
221
- "box_download_checksum": "3764a2c4ae3829aa4b50971e216c3a03736aafb2",
222
- "box_download_checksum_type": "sha1",
223
- "memory": "1024",
224
- "netmask": "255.255.255.0",
225
- "update_packages": true,
226
- "update_packages_command": "yum -y update",
227
- "shutdown": true,
228
- "shutdown_command": "/sbin/shutdown -h now"
229
- },
230
- "nodes": [
231
- {
232
- "name": "infra-puppetca",
233
- "hostname": "infra-puppetca1.example.org",
234
- "forwarded_ports": [
235
- {
236
- "guest": "8140",
237
- "host": "8140"
238
- }
239
- ],
240
- "ip": "172.16.100.5",
241
- "memory": "2048"
242
- },
243
- {
244
- "name": "infra-puppet",
245
- "hostname": "infra-puppet1.example.org",
246
- "ip": "172.16.100.6",
247
- "memory": "2048"
248
- },
249
- {
250
- "name": "www-api",
251
- "hostname": "www-api1.example.org",
252
- "ip": "172.16.100.7"
253
- }
254
- ]
255
- }
202
+ ## `controlrepo/.rizzo.yaml`
203
+
204
+ ```yaml
205
+ ---
206
+ defaults:
207
+ bootstrap_script_path: "bootstrap_puppet4.sh"
208
+ bootstrap_script_args: "-l -f `hostname -f`"
209
+ bootstrap_guest_path: "/tmp/bootstrap"
210
+ boot_timeout: 500
211
+ box: "centos7.box"
212
+ box_url: "https://vagrantboxes/centos7.box"
213
+ box_download_checksum: "3764a2c4ae3829aa4b50971e216c3a03736aafb2"
214
+ box_download_checksum_type: "sha1"
215
+ memory: "1024"
216
+ netmask: "255.255.255.0"
217
+ update_packages: true
218
+ update_packages_command: "yum -y update"
219
+ shutdown: true
220
+ shutdown_command: "/sbin/shutdown -h now"
221
+ nodes:
222
+ - name: "infra-puppetca"
223
+ hostname: "infra-puppetca1.example.org"
224
+ forwarded_ports:
225
+ - guest: "8140"
226
+ host: "8140"
227
+ ip: "172.16.100.5"
228
+ memory: "2048"
229
+ - name: "infra-puppet"
230
+ hostname: "infra-puppet1.example.org"
231
+ ip: "172.16.100.6"
232
+ memory: "2048"
233
+ - name: "www-api"
234
+ hostname: "www-api1.example.org"
235
+ ip: "172.16.100.7"
236
+ - name: "mssql1"
237
+ hostname: "mysql1.example.org"
238
+ forwarded_ports:
239
+ - guest: "5985"
240
+ host: "5985"
241
+ ip: "172.16.100.8"
242
+ windows: true
243
+ gui: true
244
+ shutdown: false
245
+ update_packages: false
246
+ box: "mwrock/Windows2016"
247
+ box_url: ~
248
+ box_download_checksum: ~
249
+ box_download_checksum_type: ~
256
250
  ```
257
251
 
258
252
  ### defaults
@@ -308,10 +302,10 @@ Path of script to be used to bootstrap a system. This is relative to
308
302
 
309
303
  Any arguments to pass to `bootstrap_script_path`.
310
304
 
311
- #### boot_timeout
305
+ #### boot_timeout (Integer)
312
306
 
313
307
  Optional parameter that sets the amount of time is seconds that Vagrant waits for
314
- a node to become available via ssh before it fails. Default is 300 seconds.
308
+ a node to become available via ssh before it fails. Default is 300 seconds.
315
309
 
316
310
  #### box
317
311
 
@@ -352,3 +346,14 @@ ensure the guest additions are working.
352
346
  #### shutdown_command
353
347
 
354
348
  The command used to shutdown the system.
349
+
350
+ #### gui
351
+
352
+ If this is set to `true` the GUI will be enabled. This brings up the
353
+ VirtualBox window and aid in debugging on Windows systems.
354
+
355
+ #### windows
356
+
357
+ If this is set to `true`, extra options will be included to let Vagrant
358
+ know this is a windows host and to use WinRM for the connect. It will
359
+ also use the `name` entry instead of `hostname`.
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'yaml'
2
2
  require 'rubocop/rake_task'
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
@@ -8,13 +8,13 @@ RSpec::Core::RakeTask.new(:spec)
8
8
 
9
9
  desc 'Validation tests'
10
10
  task :validate do
11
- puts '=== Validating JSON (*.json) files'
12
- filelist = FileList.new('**/*.json')
11
+ puts '=== Validating YAML (*.yaml) files'
12
+ filelist = FileList.new('**/*.yaml')
13
13
  filelist.exclude('.bundle/**')
14
- filelist.each do |json_file|
15
- puts json_file
16
- json = File.read(json_file)
17
- JSON.parse(json)
14
+ filelist.each do |yaml_file|
15
+ puts yaml_file
16
+ yaml = File.read(yaml_file)
17
+ YAML.parse(yaml)
18
18
  end
19
19
 
20
20
  puts "\n=== Validating ruby (*.rb, Vagrantfile, Rakefile and Gemfile) files"
@@ -0,0 +1,23 @@
1
+ ---
2
+ defaults:
3
+ bootstrap_repo_path: "/Users/jeff/projects/acme/bootstrap"
4
+ control_repos:
5
+ - "/Users/jeff/projects/acme/puppetdata"
6
+ - "/Users/jeff/projects/acme/ghoneycutt-modules"
7
+ puppetmaster:
8
+ name:
9
+ - infra-puppetfourca
10
+ - infra-puppetfour
11
+ modulepath:
12
+ - "./modules"
13
+ - "./puppetdata/modules"
14
+ - "./ghoneycutt/modules"
15
+ synced_folders:
16
+ "/repos/puppetdata":
17
+ local: "/Users/jeff/projects/acme/puppetdata"
18
+ owner: root
19
+ group: root
20
+ "/repos/ghoneycutt":
21
+ local: "/Users/jeff/projects/acme/ghoneycutt-modules"
22
+ owner: root
23
+ group: root
@@ -4,7 +4,7 @@ require 'rzo/option_parsing'
4
4
  require 'rzo/app/config'
5
5
  require 'rzo/app/generate'
6
6
  require 'rzo/app/roles'
7
- require 'json'
7
+ require 'yaml'
8
8
 
9
9
  module Rzo
10
10
  ##
@@ -8,7 +8,7 @@ module Rzo
8
8
  def run
9
9
  exit_status = 0
10
10
  load_config!
11
- write_file(opts[:output]) { |fd| fd.puts(JSON.pretty_generate(config)) }
11
+ write_file(opts[:output]) { |fd| fd.puts(config.to_yaml) }
12
12
  exit_status
13
13
  end
14
14
  end
@@ -7,15 +7,15 @@ module Rzo
7
7
  ##
8
8
  # Mix-in module providing configuration validation methods and safety
9
9
  # checking. The goal is to provide useful feedback to the end user in the
10
- # situation where ~/.rizzo.json is configured to point at directories which
10
+ # situation where ~/.rizzo.yaml is configured to point at directories which
11
11
  # do not exist, have missing keys, etc...
12
12
  # rubocop:disable Metrics/ModuleLength
13
13
  module ConfigValidation
14
14
  ## Rizzo configuration schema for the personal configuration file at
15
- # ~/.rizzo.json. Minimum necessary to load the complete configuration from
15
+ # ~/.rizzo.yaml. Minimum necessary to load the complete configuration from
16
16
  # all control repositories.
17
17
  RZO_PERSONAL_CONFIG_SCHEMA = {
18
- '$schema' => 'http://json-schema.org/draft-06/schema#',
18
+ '$schema' => 'http://json-schema.org/draft/schema#',
19
19
  title: 'Personal Configuration',
20
20
  description: 'Rizzo personal configuration file',
21
21
  type: 'object',
@@ -60,7 +60,7 @@ module Rzo
60
60
  items: { type: 'string' },
61
61
  },
62
62
  synced_folders: {
63
- '$schema' => 'http://json-schema.org/draft-06/schema#',
63
+ '$schema' => 'http://json-schema.org/draft/schema#',
64
64
  type: 'object',
65
65
  properties: {
66
66
  '/' => {},
@@ -160,7 +160,7 @@ module Rzo
160
160
 
161
161
  ##
162
162
  # Validate a personal configuration, typically originating from
163
- # ~/.rizzo.json. This configuration is necessary to build a complete
163
+ # ~/.rizzo.yaml. This configuration is necessary to build a complete
164
164
  # control repo configuration using the top level control repo. This
165
165
  # validation focuses on the minimum necessary configuration to bootstrap
166
166
  # the complete configuration, primarily the repo locations and existence.
@@ -175,9 +175,9 @@ module Rzo
175
175
 
176
176
  ##
177
177
  # Validate a complete loaded configuration. This is distinct from a base
178
- # configuration in that the JSON files in each control repository have
178
+ # configuration in that the YAML files in each control repository have
179
179
  # already been merged, in order, on top of the base configuration
180
- # originating at ~/.rizzo.json. This implements safety checking. These
180
+ # originating at ~/.rizzo.yaml. This implements safety checking. These
181
181
  # methods are expected to execute within the context of a
182
182
  # Rzo::App::Subcommand instance, therefore log methods and the parsed
183
183
  # configuration are assumed to be available.
@@ -304,3 +304,4 @@ module Rzo
304
304
  # rubocop:enable Metrics/ModuleLength
305
305
  end
306
306
  end
307
+ # rubocop:enable Style/GuardClause
@@ -17,7 +17,7 @@ module Rzo
17
17
  exit_status = 0
18
18
  load_config!
19
19
  # Vagrantfile
20
- erbfile = File.expand_path('../templates/Vagrantfile.erb', __FILE__)
20
+ erbfile = File.expand_path('templates/Vagrantfile.erb', __dir__)
21
21
  content = vagrantfile_content(erbfile, config)
22
22
  write_file(opts[:vagrantfile]) { |fd| fd.write(content) }
23
23
  say "Wrote vagrant config to #{opts[:vagrantfile]}"
@@ -33,19 +33,27 @@ module Rzo
33
33
  #
34
34
  # @return [Array<Hash>] list of agent nodes to fill in the Vagrantfile
35
35
  # template.
36
+ # rubocop:disable Metrics/AbcSize
37
+ # rubocop:disable Metrics/MethodLength
36
38
  def vagrantfile_agents(config)
37
39
  pm_settings = puppetmaster_settings(config)
38
40
  agent_nodes = [*config['nodes']].reject do |n|
39
41
  pm_settings['name'].include?(n['name'])
40
42
  end
41
43
 
42
- agent_nodes.each do |n|
43
- n.deep_merge(config['defaults'])
44
+ agent_nodes.map! do |n|
45
+ new_n = deep_convert_boolean(n)
46
+ defaults = deep_convert_boolean(config['defaults'])
47
+ new_n.deep_merge(defaults)
48
+ n = deep_unconvert_boolean(new_n)
44
49
  log.debug "puppetagent #{n['name']} = \n" + n.pretty_inspect
50
+ n
45
51
  end
46
52
 
47
53
  agent_nodes
48
54
  end
55
+ # rubocop:enable Metrics/MethodLength
56
+ # rubocop:enable Metrics/AbcSize
49
57
 
50
58
  ##
51
59
  # Return a list of puppetmaster node definitions suitable for the
@@ -58,19 +66,26 @@ module Rzo
58
66
  # Vagrantfile template.
59
67
  #
60
68
  # rubocop:disable Metrics/AbcSize
69
+ # rubocop:disable Metrics/MethodLength
61
70
  def vagrantfile_puppet_masters(config)
62
71
  pm_settings = puppetmaster_settings(config)
63
72
  pm_names = pm_settings['name']
64
73
 
65
74
  nodes = [*config['nodes']].find_all { |n| pm_names.include?(n['name']) }
66
- nodes.each do |n|
67
- n.deep_merge(config['defaults'])
68
- n.deep_merge(pm_settings)
75
+ nodes.map! do |n|
76
+ new_n = deep_convert_boolean(n)
77
+ defaults = deep_convert_boolean(config['defaults'])
78
+ new_pm_settings = deep_convert_boolean(pm_settings)
79
+ new_n.deep_merge(defaults)
80
+ new_n.deep_merge(new_pm_settings)
81
+ n = deep_unconvert_boolean(new_n)
69
82
  n[:puppetmaster] = true
70
83
  log.debug "puppetmaster #{n['name']} = \n" + n.pretty_inspect
84
+ n
71
85
  end
72
86
  end
73
87
  # rubocop:enable Metrics/AbcSize
88
+ # rubocop:enable Metrics/MethodLength
74
89
 
75
90
  ##
76
91
  # Return the proxy configuration exception list as a string, or nil if not set.
@@ -82,6 +97,7 @@ module Rzo
82
97
  def proxy_config(config)
83
98
  # Proxy Setting
84
99
  return nil unless config['config']
100
+
85
101
  config['config']['no_proxy'] || DEFAULT_NO_PROXY
86
102
  end
87
103
 
@@ -132,6 +148,46 @@ module Rzo
132
148
 
133
149
  # Constants used by the Vagrantfile.erb template.
134
150
  DEFAULT_NO_PROXY = 'localhost,127.0.0.1'.freeze
151
+
152
+ private
153
+
154
+ ##
155
+ # Convert boolean to string for deep_merge
156
+ # rubocop:disable Metrics/MethodLength
157
+ def deep_convert_boolean(hash)
158
+ new_hash = {}
159
+ hash.each_pair do |key, value|
160
+ if value.is_a?(Hash)
161
+ new_hash[key] = deep_convert_boolean(value)
162
+ elsif value.is_a?(TrueClass)
163
+ new_hash[key] = 'true'
164
+ elsif value.is_a?(FalseClass)
165
+ new_hash[key] = 'false'
166
+ else
167
+ new_hash[key] = value
168
+ end
169
+ end
170
+ return new_hash
171
+ end
172
+
173
+ ##
174
+ # Convert boolean strings to boolean for use after deep_merge
175
+ def deep_unconvert_boolean(hash)
176
+ new_hash = {}
177
+ hash.each_pair do |key, value|
178
+ if value.is_a?(Hash)
179
+ new_hash[key] = deep_unconvert_boolean(value)
180
+ elsif value == 'true'
181
+ new_hash[key] = true
182
+ elsif value == 'false'
183
+ new_hash[key] = false
184
+ else
185
+ new_hash[key] = value
186
+ end
187
+ end
188
+ return new_hash
189
+ end
190
+ # rubocop:enable Metrics/MethodLength
135
191
  end
136
192
  end
137
193
  end
@@ -14,8 +14,10 @@ module Rzo
14
14
  # name. This is the same as the name of the VM.
15
15
  def roles
16
16
  return [] unless nodes = config['nodes']
17
+
17
18
  nodes.each_with_object([]) do |node, a|
18
19
  next unless node['name']
20
+
19
21
  a << node['name']
20
22
  end
21
23
  end
@@ -2,6 +2,7 @@ require 'pathname'
2
2
  require 'rzo/logging'
3
3
  require 'deep_merge'
4
4
  require 'rzo/app/config_validation'
5
+ require 'yaml'
5
6
  module Rzo
6
7
  class App
7
8
  # The base class for subcommands
@@ -13,7 +14,7 @@ module Rzo
13
14
  # The options hash injected from the application controller via the
14
15
  # initialize method.
15
16
  attr_reader :opts
16
- # The Rizzo configuration after loading ~/.rizzo.json (--config).
17
+ # The Rizzo configuration after loading ~/.rizzo.yaml (--config).
17
18
  # See #load_config!
18
19
  attr_reader :config
19
20
  # The present working directory at startup
@@ -24,10 +25,11 @@ module Rzo
24
25
  def self.load_rizzo_config(fpath)
25
26
  config_file = Pathname.new(fpath).expand_path
26
27
  raise ErrorAndExit, "Cannot read config file #{config_file}" unless config_file.readable?
27
- config = JSON.parse(config_file.read)
28
+
29
+ config = YAML.safe_load(config_file.read)
28
30
  log.debug "Loaded #{config_file}"
29
31
  config
30
- rescue JSON::ParserError => e
32
+ rescue Psych::SyntaxError => e
31
33
  raise ErrorAndExit, "Could not parse rizzo config #{config_file} #{e.message}"
32
34
  end
33
35
 
@@ -59,14 +61,14 @@ module Rzo
59
61
  # Load rizzo configuration. Populate @config.
60
62
  #
61
63
  # Read rizzo configuration by looping through control repos and stopping
62
- # at first match and merge on top of local, defaults (~/.rizzo.json)
64
+ # at first match and merge on top of local, defaults (~/.rizzo.yaml)
63
65
  def load_config!
64
66
  config = load_rizzo_config(opts[:config])
65
67
  validate_personal_config!(config)
66
68
  repos = reorder_repos(config['control_repos'])
67
69
  config['control_repos'] = repos
68
70
  @config = load_repo_configs(config, repos)
69
- debug "Merged configuration: \n#{JSON.pretty_generate(@config)}"
71
+ debug "Merged configuration: \n#{@config.to_yaml}"
70
72
  # TODO: Move these validations to an instance method?
71
73
  validate_complete_config!(@config)
72
74
  # validate_forwarded_ports(@config)
@@ -75,7 +77,7 @@ module Rzo
75
77
  end
76
78
 
77
79
  ##
78
- # Given a list of repository paths, load .rizzo.json from the root of each
80
+ # Given a list of repository paths, load .rizzo.yaml from the root of each
79
81
  # repository and return the result merged onto config. The merging
80
82
  # behavior is implemented by
81
83
  # [deep_merge](http://www.rubydoc.info/gems/deep_merge/1.1.1)
@@ -83,12 +85,12 @@ module Rzo
83
85
  # @param [Hash] config the starting config hash. Repo config maps will be
84
86
  # merged on top of this starting map.
85
87
  #
86
- # @param [Array] repos the list of repositories to load .rizzo.json from.
88
+ # @param [Array] repos the list of repositories to load .rizzo.yaml from.
87
89
  #
88
90
  # @return [Hash] the merged configuration hash.
89
91
  def load_repo_configs(config = {}, repos = [])
90
92
  repos.each_with_object(config.dup) do |repo, hsh|
91
- fp = Pathname.new(repo).expand_path + '.rizzo.json'
93
+ fp = Pathname.new(repo).expand_path + '.rizzo.yaml'
92
94
  if readable?(fp.to_s)
93
95
  hsh.deep_merge!(load_rizzo_config(fp.to_s))
94
96
  else
@@ -130,7 +132,7 @@ module Rzo
130
132
  # Helper to raise a duplicate port error
131
133
  def raise_port_err(port, node)
132
134
  raise ErrorAndExit, "host port #{port} on node #{node} " \
133
- 'is a duplicate. Ports must be unique. Check .rizzo.json ' \
135
+ 'is a duplicate. Ports must be unique. Check .rizzo.yaml ' \
134
136
  'files in each control repository for duplicate forwarded_ports entries.'
135
137
  end
136
138
 
@@ -138,7 +140,7 @@ module Rzo
138
140
  # Helper to raise a duplicate port error
139
141
  def raise_ip_err(ip, node)
140
142
  raise ErrorAndExit, "host ip #{ip} on node #{node} " \
141
- 'is a duplicate. IP addresses must be unique. Check .rizzo.json ' \
143
+ 'is a duplicate. IP addresses must be unique. Check .rizzo.yaml ' \
142
144
  'files in each control repository for duplicate ip entries'
143
145
  end
144
146
 
@@ -175,22 +177,23 @@ module Rzo
175
177
  ##
176
178
  # Memoized method to return the fully qualified path to the current rizzo
177
179
  # project directory, based on the pwd. The project directory is the
178
- # dirname of the full path to a `.rizzo.json` config file. Return false
179
- # if not a project directory. ~/.rizzo.json is considered a personal
180
+ # dirname of the full path to a `.rizzo.yaml` config file. Return false
181
+ # if not a project directory. ~/.rizzo.yaml is considered a personal
180
182
  # configuration and not a project configuration.
181
183
  #
182
184
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
183
185
  def project_dir(path)
184
186
  return @project_dir unless @project_dir.nil?
185
- rizzo_file = Pathname.new("#{path}/.rizzo.json")
186
- personal_config = Pathname.new(File.expand_path('~/.rizzo.json'))
187
+
188
+ rizzo_file = Pathname.new("#{path}/.rizzo.yaml")
189
+ personal_config = Pathname.new(File.expand_path('~/.rizzo.yaml'))
187
190
  iterations = 0
188
191
  while @project_dir.nil? && iterations < 100
189
192
  iterations += 1
190
193
  if readable?(rizzo_file.to_s) && rizzo_file != personal_config
191
194
  @project_dir = rizzo_file.dirname.to_s
192
195
  else
193
- rizzo_file = rizzo_file.dirname.dirname + '.rizzo.json'
196
+ rizzo_file = rizzo_file.dirname.dirname + '.rizzo.yaml'
194
197
  @project_dir = false if rizzo_file.dirname.root?
195
198
  end
196
199
  end
@@ -211,5 +214,6 @@ module Rzo
211
214
  end
212
215
  end
213
216
  end
217
+ # rubocop:enable Metrics/ClassLength
214
218
  end
215
219
  end
@@ -13,16 +13,35 @@ Vagrant.configure(2) do |config|
13
13
 
14
14
  config.vm.define <%= nc['name'].inspect %>, autostart: false do |cfg|
15
15
  cfg.vm.box = <%= nc['box'].inspect %>
16
+ <%- if nc['box_url'] -%>
16
17
  cfg.vm.box_url = <%= nc['box_url'].inspect %>
18
+ <%- end -%>
19
+ <%- if nc['box_download_checksum'] -%>
17
20
  cfg.vm.box_download_checksum = <%= nc['box_download_checksum'].inspect %>
21
+ <%- end -%>
22
+ <%- if nc['box_download_checksum_type'] -%>
18
23
  cfg.vm.box_download_checksum_type = <%= nc['box_download_checksum_type'].inspect %>
24
+ <%- end -%>
19
25
  <%- if nc['boot_timeout'] -%>
20
26
  cfg.vm.boot_timeout = <%= nc['boot_timeout'].inspect %>
21
27
  <%- end -%>
28
+ <%- if nc['memory'] || nc['gui'] -%>
22
29
  cfg.vm.provider :virtualbox do |vb|
30
+ <%- if nc['memory'] -%>
23
31
  vb.customize ['modifyvm', :id, '--memory', <%= nc['memory'].inspect %>]
32
+ <%- end -%>
33
+ <%- if nc['gui'] -%>
34
+ vb.gui = <%= nc['gui'].inspect %>
35
+ <%- end -%>
24
36
  end
37
+ <%- end -%>
38
+ <%- if nc['windows'] == true -%>
39
+ cfg.vm.guest = :windows
40
+ cfg.vm.communicator = :winrm
41
+ cfg.vm.hostname = <%= nc['name'].inspect %>
42
+ <%- else -%>
25
43
  cfg.vm.hostname = <%= nc['hostname'].inspect %>
44
+ <%- end -%>
26
45
  cfg.vm.network 'private_network',
27
46
  ip: <%= nc['ip'].inspect %>,
28
47
  netmask: <%= nc['netmask'].inspect %>
@@ -40,17 +59,21 @@ Vagrant.configure(2) do |config|
40
59
  cfg.vm.synced_folder <%= nc['bootstrap_repo_path'].inspect %>,
41
60
  <%= nc['bootstrap_guest_path'].inspect %>,
42
61
  owner: 'vagrant', group: 'root'
62
+ <%- end -%>
43
63
  <%- if nc[:puppetmaster] -%>
44
64
  cfg.vm.provision 'shell', inline: <%= "echo 'modulepath = #{nc['modulepath'].join(':')}' > #{nc['bootstrap_guest_path']}/environment.conf".inspect %>
45
65
  <%- end -%>
46
- cfg.vm.provision 'shell', inline: <%= "/bin/bash #{nc['bootstrap_guest_path']}/#{nc['bootstrap_script_path']} #{nc['bootstrap_script_args']}".inspect %>
47
- <%- if nc['update_packages'] -%>
66
+ <%- if nc['windows'] == true -%>
67
+ cfg.vm.provision 'shell', inline: <%= "#{nc['bootstrap_guest_path']}\\#{nc['bootstrap_script_path']} #{nc['bootstrap_script_args']}".inspect %>
68
+ <%- else -%>
69
+ cfg.vm.provision 'shell', inline: <%= "/bin/bash #{nc['bootstrap_guest_path']}/#{nc['bootstrap_script_path']} #{nc['bootstrap_script_args']}".inspect.chomp %>
70
+ <%- end -%>
71
+ <%- if nc['update_packages'] == true -%>
48
72
  cfg.vm.provision 'shell', inline: <%= nc['update_packages_command'].inspect %>
49
73
  <%- end -%>
50
- <%- if nc['shutdown'] -%>
74
+ <%- if nc['shutdown'] == true -%>
51
75
  cfg.vm.provision 'shell', inline: <%= nc['shutdown_command'].inspect %>
52
76
  <%- end -%>
53
- <%- end -%>
54
77
  end
55
78
  <%- end -%>
56
79
  end
@@ -66,7 +66,7 @@ module Rzo
66
66
  opt :debug, 'Set log level to DEBUG {RZO_DEBUG="true"}',
67
67
  default: env['RZO_DEBUG'] == 'true'
68
68
  opt :config, 'Rizzo config file {RZO_CONFIG}',
69
- default: env['RZO_CONFIG'] || '~/.rizzo.json'
69
+ default: env['RZO_CONFIG'] || '~/.rizzo.yaml'
70
70
  end
71
71
  end
72
72
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
@@ -123,11 +123,12 @@ module Rzo
123
123
  usage: #{NAME} [GLOBAL OPTIONS] SUBCOMMAND [ARGS]
124
124
  Sub Commands:
125
125
 
126
- config Print out the combined rizzo json config
126
+ config Print out the combined rizzo yaml config
127
127
  generate Initialize Vagrantfile in top control repo
128
128
  roles Output all roles defined in the combined config
129
129
 
130
130
  Global options: (Note, command line arguments supersede ENV vars in {}'s)
131
131
  BANNERMSG
132
+ # rubocop:enable Layout/IndentHeredoc
132
133
  end
133
134
  end
@@ -5,7 +5,7 @@ module Rzo
5
5
  # The authoritative location of the rzo version. It should be possible to
6
6
  # `require 'rizzo/version'` and access `Rizzo::VERSION` from third party
7
7
  # libraries and the gemspec. The version is defined as a Semantic Version.
8
- VERSION = '0.7.0'.freeze
8
+ VERSION = '0.8.0'.freeze
9
9
 
10
10
  ##
11
11
  # Return the SemVer string, e.g. `"0.1.0"`
@@ -1,4 +1,4 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'rzo/version'
4
4
 
@@ -40,6 +40,5 @@ Gem::Specification.new do |spec|
40
40
  spec.add_development_dependency 'simplecov', '~> 0.14'
41
41
  spec.add_development_dependency 'yard', '~> 0.9'
42
42
  spec.add_dependency 'deep_merge', '~> 1.1'
43
- spec.add_dependency 'json', '~> 2.1'
44
- spec.add_dependency 'json-schema', '~> 2.8'
43
+ spec.add_dependency 'json-schema', '>= 2.8.1'
45
44
  end
@@ -90,19 +90,19 @@ debug() {
90
90
  echo -e "${BLUE}Debug:${NC} $msg" >&2
91
91
  }
92
92
 
93
- # Move ~/.rizzo.json out of the way if it exists
94
- if [[ -e ~/.rizzo.json ]]; then
95
- debug "Moving ~/.rizzo.json to ~/.rizzo.json.$STAMP"
96
- mv -f ~/.rizzo.json ~/.rizzo.json.$STAMP
93
+ # Move ~/.rizzo.yaml out of the way if it exists
94
+ if [[ -e ~/.rizzo.yaml ]]; then
95
+ debug "Moving ~/.rizzo.yaml to ~/.rizzo.yaml.$STAMP"
96
+ mv -f ~/.rizzo.yaml ~/.rizzo.yaml.$STAMP
97
97
  fi
98
98
 
99
99
  # Clean up our temp directory
100
100
  scratch=$(mktemp -d)
101
101
  export TMPDIR="$scratch"
102
102
  finish() {
103
- if [[ -e ~/.rizzo.json.$STAMP ]]; then
104
- mv -f ~/.rizzo.json.$STAMP ~/.rizzo.json
105
- debug "Moved ~/.rizzo.json.$STAMP to ~/.rizzo.json"
103
+ if [[ -e ~/.rizzo.yaml.$STAMP ]]; then
104
+ mv -f ~/.rizzo.yaml.$STAMP ~/.rizzo.yaml
105
+ debug "Moved ~/.rizzo.yaml.$STAMP to ~/.rizzo.yaml"
106
106
  fi
107
107
  if [[ -d "$scratch" ]]; then
108
108
  rm -rf "$scratch"
@@ -193,26 +193,38 @@ fi
193
193
  # Puppet data repositories used by rizzo
194
194
  PUPPETDATA="${TMPDIR}/git/puppetdata"
195
195
 
196
- desc "With a valid ~/.rizzo.json file looking like:"
197
- cat > ~/.rizzo.json <<EOCONFIG
198
- {
199
- "defaults": { "bootstrap_repo_path": "${HOME}/git/bootstrap" },
200
- "control_repos": [ "${PUPPETDATA}", "${HOME}/git/ghoneycutt-modules" ],
201
- "puppetmaster": {
202
- "name": [ "puppetca", "puppet" ],
203
- "modulepath": [ "./modules", "./puppetdata/modules", "./ghoneycutt/modules" ],
204
- "synced_folders": {
205
- "/repos/puppetdata": { "local": "${PUPPETDATA}", "owner": "root", "group": "root" },
206
- "/repos/ghoneycutt": { "local": "${HOME}/git/ghoneycutt-modules", "owner": "root", "group": "root" }
207
- }
208
- }
209
- }
196
+ desc "With a valid ~/.rizzo.yaml file looking like:"
197
+ cat > ~/.rizzo.yaml <<EOCONFIG
198
+ ---
199
+ defaults:
200
+ box: el6-rc5
201
+ bootstrap_repo_path: "${HOME}/git/bootstrap"
202
+ control_repos:
203
+ - ${PUPPETDATA}
204
+ - ${HOME}/git/ghoneycutt-modules
205
+ puppetmaster:
206
+ name:
207
+ - puppetca
208
+ - puppet
209
+ modulepath:
210
+ - ./modules
211
+ - ./puppetdata/modules
212
+ - ./ghoneycutt/modules
213
+ synced_folders:
214
+ /repos/puppetdata:
215
+ local: "${PUPPETDATA}"
216
+ owner: "root"
217
+ group: "root"
218
+ /repos/ghoneycutt:
219
+ local: "${HOME}/git/ghoneycutt-modules"
220
+ owner: "root"
221
+ group: "root"
210
222
  EOCONFIG
211
223
  # Print out the config
212
- expected=$(mktemp -t XXXXXX.rizzo.json)
213
- ruby -rjson -e 'puts JSON.pretty_generate(JSON.parse(ARGF.read))' ~/.rizzo.json | tee $expected
224
+ expected=$(mktemp -t XXXXXX.rizzo.yaml)
225
+ ruby -ryaml -e 'puts YAML.safe_load(ARGF.read).to_yaml' ~/.rizzo.yaml | tee $expected
214
226
 
215
- desc "rzo config is expected to pretty generate the JSON config"
227
+ desc "rzo config is expected to pretty generate the YAML config"
216
228
  stdout=$(mktemp -t XXXXXX.stdout)
217
229
  stderr=$(mktemp -t XXXXXX.stderr)
218
230
  rzo config > $stdout 2> $stderr
@@ -264,7 +276,7 @@ else
264
276
  pass "It does."
265
277
  fi
266
278
 
267
- desc "rzo roles with no personal .rizzo.json is expected to warn"
279
+ desc "rzo roles with no personal .rizzo.yaml is expected to warn"
268
280
  stdout=$(mktemp -t XXXXXX.stdout)
269
281
  stderr=$(mktemp -t XXXXXX.stderr)
270
282
  rzo roles 2> $stderr > $stdout
@@ -278,7 +290,7 @@ if ! [[ -d "$PUPPETDATA" ]]; then
278
290
  mkdir -p "$PUPPETDATA"
279
291
  debug "Created $PUPPETDATA"
280
292
  fi
281
- echo '{"nodes":[{"name":"puppetca"}]}' > ${PUPPETDATA}/.rizzo.json
293
+ echo '{"nodes":[{"name":"puppetca"}]}' > ${PUPPETDATA}/.rizzo.yaml
282
294
 
283
295
  stdout=$(mktemp -t XXXXXX.stdout)
284
296
  stderr=$(mktemp -t XXXXXX.stderr)
@@ -304,13 +316,7 @@ Vagrant.configure(2) do |config|
304
316
  end
305
317
 
306
318
  config.vm.define "puppetca", autostart: false do |cfg|
307
- cfg.vm.box = nil
308
- cfg.vm.box_url = nil
309
- cfg.vm.box_download_checksum = nil
310
- cfg.vm.box_download_checksum_type = nil
311
- cfg.vm.provider :virtualbox do |vb|
312
- vb.customize ['modifyvm', :id, '--memory', nil]
313
- end
319
+ cfg.vm.box = "el6-rc5"
314
320
  cfg.vm.hostname = nil
315
321
  cfg.vm.network 'private_network',
316
322
  ip: nil,
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+ require 'yaml'
5
+
6
+ input = ARGV[0]
7
+
8
+ json_data = File.read(input)
9
+ data = JSON.parse(json_data)
10
+ output = input.gsub('.json', '.yaml')
11
+ puts output
12
+ File.open(output, 'w') do |o|
13
+ o.write(data.to_yaml)
14
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rzo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garrett Honeycutt
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-11-05 00:00:00.000000000 Z
12
+ date: 2018-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guard
@@ -193,34 +193,20 @@ dependencies:
193
193
  - - "~>"
194
194
  - !ruby/object:Gem::Version
195
195
  version: '1.1'
196
- - !ruby/object:Gem::Dependency
197
- name: json
198
- requirement: !ruby/object:Gem::Requirement
199
- requirements:
200
- - - "~>"
201
- - !ruby/object:Gem::Version
202
- version: '2.1'
203
- type: :runtime
204
- prerelease: false
205
- version_requirements: !ruby/object:Gem::Requirement
206
- requirements:
207
- - - "~>"
208
- - !ruby/object:Gem::Version
209
- version: '2.1'
210
196
  - !ruby/object:Gem::Dependency
211
197
  name: json-schema
212
198
  requirement: !ruby/object:Gem::Requirement
213
199
  requirements:
214
- - - "~>"
200
+ - - ">="
215
201
  - !ruby/object:Gem::Version
216
- version: '2.8'
202
+ version: 2.8.1
217
203
  type: :runtime
218
204
  prerelease: false
219
205
  version_requirements: !ruby/object:Gem::Requirement
220
206
  requirements:
221
- - - "~>"
207
+ - - ">="
222
208
  - !ruby/object:Gem::Version
223
- version: '2.8'
209
+ version: 2.8.1
224
210
  description: Rizzo (rzo) is a tool for working with Vagrant and layered Puppet control
225
211
  repos
226
212
  email:
@@ -247,7 +233,7 @@ files:
247
233
  - bin/setup
248
234
  - exe/rizzo
249
235
  - exe/rzo
250
- - ext/_rizzo.json
236
+ - ext/_rizzo.yaml
251
237
  - lib/rzo.rb
252
238
  - lib/rzo/app.rb
253
239
  - lib/rzo/app/config.rb
@@ -262,6 +248,7 @@ files:
262
248
  - lib/rzo/version.rb
263
249
  - rzo.gemspec
264
250
  - scripts/functional_gem_behavior.sh
251
+ - scripts/json2yaml.rb
265
252
  homepage: https://github.com/ghoneycutt/rizzo
266
253
  licenses:
267
254
  - Apache-2.0
@@ -283,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
283
270
  version: '0'
284
271
  requirements: []
285
272
  rubyforge_project:
286
- rubygems_version: 2.4.8
273
+ rubygems_version: 2.6.14.1
287
274
  signing_key:
288
275
  specification_version: 4
289
276
  summary: Rizzo (rzo) is a tool for working with Vagrant and layered Puppet control
@@ -1,32 +0,0 @@
1
- {
2
- "defaults": {
3
- "bootstrap_repo_path": "/Users/jeff/projects/acme/bootstrap"
4
- },
5
- "control_repos": [
6
- "/Users/jeff/projects/acme/puppetdata",
7
- "/Users/jeff/projects/acme/ghoneycutt-modules"
8
- ],
9
- "puppetmaster": {
10
- "name": [
11
- "infra-puppetfourca",
12
- "infra-puppetfour"
13
- ],
14
- "modulepath": [
15
- "./modules",
16
- "./puppetdata/modules",
17
- "./ghoneycutt/modules"
18
- ],
19
- "synced_folders": {
20
- "/repos/puppetdata": {
21
- "local": "/Users/jeff/projects/acme/puppetdata",
22
- "owner": "root",
23
- "group": "root"
24
- },
25
- "/repos/ghoneycutt": {
26
- "local": "/Users/jeff/projects/acme/ghoneycutt-modules",
27
- "owner": "root",
28
- "group": "root"
29
- }
30
- }
31
- }
32
- }