octocatalog-diff 0.5.3 → 0.5.4

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: 1d03d7df9d9a9ef8658b7c698fa39462ed377d96
4
- data.tar.gz: 47549febe31a305cafe0cef9e6db6aba4ae33e0d
3
+ metadata.gz: 4632d74c4bd84807f92cb770854c95124c8c0ae8
4
+ data.tar.gz: 4f58f8e014f209089125a4c8dacdcd0320f0c9a6
5
5
  SHA512:
6
- metadata.gz: 3f5c02689fd13a050b1458f64ebb53512a96c200346407e2c2de3dfab010c7cd0aa64cea4100b96c4009dd06a78e67c8d98f7d3b0d3f5c1ed95939f955e58ef2
7
- data.tar.gz: e6f91d1779758f485dda6c11c104f75ca5484c53af4840dd01a7d6f46cf40f084fb517c3f5389024c9615a8085a7a640c90640fcb2ac3090ab5945fbdd93b2d5
6
+ metadata.gz: e68c927375de0a95e3c1e034febfa341228bfabb413b7cb1fcd506306d74a9d9ace8d2fd2ef39b48c2ed13b945094566146d1c8d86d4c71f9ccab15e678a20c6
7
+ data.tar.gz: 8004544d6fbb3b0d1c985d2994f98d8b22382179038ff60c5ea5c9c06e3b196edf37fa3a202fe6d3982c40e2b6e87b3dfa0646cf42b5ead0f3d45a976d0ff529
data/.version CHANGED
@@ -1 +1 @@
1
- 0.5.3
1
+ 0.5.4
data/doc/CHANGELOG.md CHANGED
@@ -1,7 +1,40 @@
1
1
  # octocatalog-diff change log
2
2
 
3
- | Version | Date | Description / Changes |
4
- | ------- | ---- | ----------- |
5
- | 0.5.3 | 2016-10-31 | https://github.com/github/octocatalog-diff/pull/10: facts terminus optimization |
6
- | 0.5.2 | - | Unreleased internal version |
7
- | 0.5.1 | 2016-10-20 | Initial release |
3
+ <table><thead>
4
+ <tr>
5
+ <th>Version</th>
6
+ <th>Date</th>
7
+ <th>Description / Changes</th>
8
+ </tr>
9
+ </thead><tbody>
10
+ <tr valign=top>
11
+ <td>0.5.4</td>
12
+ <td>2016-11-07</td>
13
+ <td>
14
+ <ul>
15
+ <li><a href="https://github.com/github/octocatalog-diff/pull/16">https://github.com/github/octocatalog-diff/pull/16</a>: environment running <code>puppet --version</code></li>
16
+ <li><a href="https://github.com/github/octocatalog-diff/pull/5">https://github.com/github/octocatalog-diff/pull/5</a>: bootstrap debugging</li>
17
+ <li><a href="https://github.com/github/octocatalog-diff/pull/17">https://github.com/github/octocatalog-diff/pull/17</a>: hiera simplification and <code>--hiera-path</code> option</li>
18
+ </ul>
19
+ </td>
20
+ </tr>
21
+ <tr valign=top>
22
+ <td>0.5.3</td>
23
+ <td>2016-10-31</td>
24
+ <td>
25
+ <ul>
26
+ <li><a href="https://github.com/github/octocatalog-diff/pull/10">https://github.com/github/octocatalog-diff/pull/10</a>: facts terminus optimization</li>
27
+ </ul>
28
+ </td>
29
+ </tr>
30
+ <tr valign=top>
31
+ <td>0.5.2</td>
32
+ <td>-</td>
33
+ <td>Unreleased internal version</td>
34
+ </tr>
35
+ <tr valign=top>
36
+ <td>0.5.1</td>
37
+ <td>2016-10-20</td>
38
+ <td>Initial release</td>
39
+ </tr>
40
+ </tbody></table>
@@ -0,0 +1,39 @@
1
+ # Configuring octocatalog-diff to use Hiera path stripping
2
+
3
+ This is a different, and potentially more complex, alternative to `--hiera-path` / `settings[:hiera_path]` described in the [Configuring octocatalog-diff to use Hiera](/doc/configuration-hiera.md) document. Unless you have a very good reason, you should prefer to use the instructions in that document instead of using the more complicated option that is described herein.
4
+
5
+ The command line option `--hiera-path-strip PATH` allows you to manipulate directory paths for the JSON or YAML hiera backends. This setting only has an effect on the copy of hiera.yaml that is copied into the temporary compilation directory. This does not make any changes to the actual source hiera.yaml file on your system or in your checkout.
6
+
7
+ For example, perhaps your production hiera.yaml file has entries such as the following:
8
+
9
+ ```
10
+ ---
11
+ :backends:
12
+ - yaml
13
+ :hierarchy:
14
+ - "nodes/%{::trusted.certname}"
15
+ - common
16
+
17
+ :yaml:
18
+ :datadir: /etc/puppetlabs/code/environments/%{environment}/hieradata
19
+ ```
20
+
21
+ However, when you run octocatalog-diff on a machine that is not a Puppet master, the hiera data will not actually be found in `/etc/puppetlabs/code/environments/production/hieradata`, but rather in a directory called `hieradata` relative to the checkout of your Puppet code.
22
+
23
+ Specifying `--hiera-path-strip PATH` causes octocatalog-diff to munge the datadir for the YAML and JSON configuration. The correct command in this case is now:
24
+
25
+ ```
26
+ bin/octocatalog-diff --hiera-config hiera.yaml --hiera-path-strip /etc/puppetlabs/code
27
+ ```
28
+
29
+ ```
30
+ ---
31
+ :backends:
32
+ - yaml
33
+ :hierarchy:
34
+ - "nodes/%{::trusted.certname}"
35
+ - common
36
+
37
+ :yaml:
38
+ :datadir: /var/tmp/puppet-compile-dir-92347829847/environments/%{environment}/hieradata
39
+ ```
@@ -10,7 +10,7 @@ Before you start, please understand how octocatalog-diff compiles a catalog:
10
10
  - It compiles the catalog, based on the temporary directory, for environment=production
11
11
  - It removes the temporary directory
12
12
 
13
- ## Configuring the path to hiera.yaml
13
+ ## Configuring the location of hiera.yaml
14
14
 
15
15
  The command line option `--hiera-config PATH` allows you to set the path to hiera.yaml.
16
16
 
@@ -21,22 +21,26 @@ You may specify this as either an absolute or a relative path.
21
21
  octocatalog-diff knows to use a relative path when the supplied path for `--hiera-config` does not start with a `/`.
22
22
 
23
23
  ```
24
- bin/octocatalog-diff --hiera-config config/hiera.yaml ...
24
+ bin/octocatalog-diff --hiera-config hiera.yaml ...
25
25
  ```
26
26
 
27
- The path is relative to a checkout of your Puppet repository. As per the example in the introduction, say that octocatalog-diff is using a temporary directory of `/var/tmp/puppet-compile-dir-92347829847` when compiling a Puppet catalog. With the setting above, it will copy `config/hiera.yaml` (relative to your Puppet checkout) into the temporary directory.
27
+ The path is relative to a checkout of your Puppet repository. With the setting above, it will use the file named `hiera.yaml` that is at the top level
28
+ of your Puppet checkout.
28
29
 
29
- If you use Puppet to manage your hiera.yaml file on Puppet masters, perhaps it is found in one of the modules in your code. In that case, you may use syntax like:
30
+ Perhaps your hiera.yaml file is in a subdirectory of your Puppet checkout. In that case, just use the relative directory path. Be sure not to add a leading `/` though,
31
+ because you don't want octocatalog-diff to treat it as an absolute path. In the following example, suppose you have a top level directory called `config` and your
32
+ `hiera.yaml` file is contained within it. You could then use:
30
33
 
31
34
  ```
32
- bin/octocatalog-diff --hiera-config modules/puppet/files/hiera.yaml ...
35
+ bin/octocatalog-diff --hiera-config config/hiera.yaml ...
33
36
  ```
34
37
 
35
38
  If you are specifying the hiera.yaml path in the [configuration file](/doc/configuration.md), you will instead set the variable like this:
36
39
 
37
40
  ```
41
+ settings[:hiera_config] = 'hiera.yaml'
42
+ (or)
38
43
  settings[:hiera_config] = 'config/hiera.yaml'
39
- settings[:hiera_config] = 'modules/puppet/files/hiera.yaml'
40
44
  ```
41
45
 
42
46
  octocatalog-diff will fail if you specify a hiera configuration location that cannot be opened.
@@ -57,47 +61,35 @@ You may specify this as either an absolute or a relative path.
57
61
  settings[:hiera_config] = '/etc/puppetlabs/puppet/hiera.yaml'
58
62
  ```
59
63
 
60
- Please note that octocatalog-diff will copy the file from the specified location into the compile directory. Since this hiera.yaml file is not copied from your Puppet repo, there is no way to compile the "to" and "from" branches using different hiera.yaml files. Furthermore, you are responsible for getting this file into place on any machine that will run octocatalog-diff.
64
+ Please note that octocatalog-diff will copy the file from the specified location into the compile directory. Since this hiera.yaml file is not copied from your Puppet repo, there is no way to compile the "to" and "from" branches using different hiera.yaml files. Furthermore, you are responsible for getting this file into place on any machine that will run octocatalog-diff. An absolute path may make octocatalog-diff work correctly on your Puppet master servers, but the structure may differ on other machines where you wish to run the utility.
61
65
 
62
66
  We strongly recommend that you version-control your hiera.yaml file within your Puppet repository, and use the relative path option described above.
63
67
 
68
+ ## Configuring the directory in your repository in which hiera data files are found
69
+
70
+ The command line option `--hiera-path PATH` allows you to set the directory path, relative to the checkout of your Puppet repository, of your Hiera YAML/JSON data files.
71
+
72
+ If you are using the out-of-the-box Puppet Enterprise configuration, or the [Puppet Control Repo template](https://github.com/puppetlabs/control-repo), then the correct setting here is simply 'hieradata'.
73
+
74
+ You must specify this as a relative path. octocatalog-diff knows to use a relative path when the supplied path for `--hiera-path` does not start with a `/`.
75
+
76
+ ```
77
+ bin/octocatalog-diff --hiera-path hieradata ...
78
+ ```
79
+
80
+ The path is relative to a checkout of your Puppet repository. With the setting above, it will look for Hiera data in a directory called `hieradata` that is at the top level
81
+ of your Puppet checkout.
82
+
83
+ If you are specifying the Hiera data path in the [configuration file](/doc/configuration.md), you will instead set the variable like this:
84
+
85
+ ```
86
+ settings[:hiera_path] = 'hieradata'
87
+ ```
88
+
89
+ octocatalog-diff will fail if you specify a path that is not a directory.
90
+
64
91
  ## Configuring the prefix path to strip
65
92
 
66
- The command line option `--hiera-path-strip PATH` allows you to manipulate directory paths for the JSON or YAML hiera backends. This setting only has an effect on the copy of hiera.yaml that is copied into the temporary compilation directory. This does not make any changes to the actual source hiera.yaml file on your system or in your checkout.
67
-
68
- For example, perhaps your production hiera.yaml file has entries such as the following:
69
-
70
- ```
71
- :backends:
72
- - yaml
73
- :yaml:
74
- :datadir: /var/lib/puppet/environments/%{::environment}/hieradata
75
- :hierarchy:
76
- - servers/%{::fqdn}
77
- - platform/%{::virtual}
78
- - datacenter/%{::datacenter}
79
- - os/%{::operatingsystem}
80
- - common
81
- ```
82
-
83
- However, when you run octocatalog-diff, the hiera data will not actually be found in `/var/lib/puppet/environments/production/hieradata`, but rather in a directory called `environments/production/hieradata` relative to the checkout of your Puppet code.
84
-
85
- Specifying `--hiera-path-strip PATH` causes octocatalog-diff will rewrite the datadir for the YAML and JSON configuration. In the example above, the correct setting is `--hiera-path-strip /var/lib/puppet`, which will result in the following configuration in the hiera.yaml file:
86
-
87
- ```
88
- bin/octocatalog-diff --hiera-config environments/production/config/hiera.yaml --hiera-path-strip /var/lib/puppet
89
- ```
90
-
91
- ```
92
- # This is the temporary hiera.yaml file used for octocatalog-diff catalog compilation
93
- :backends:
94
- - yaml
95
- :yaml:
96
- :datadir: /var/tmp/puppet-compile-dir-92347829847/environments/%{::environment}/hieradata
97
- :hierarchy:
98
- - servers/%{::fqdn}
99
- - platform/%{::virtual}
100
- - datacenter/%{::datacenter}
101
- - os/%{::operatingsystem}
102
- - common
103
- ```
93
+ This is a different, and potentially more complex, alternative to `--hiera-path` / `settings[:hiera_path]` described in the prior section. Unless you have a very good reason, you should prefer to use the instructions above.
94
+
95
+ If you need to use the more complex path strip alternative, see: [Configuring octocatalog-diff to use Hiera path stripping](/doc/advanced-hiera-path-stripping.md).
data/doc/configuration.md CHANGED
@@ -30,7 +30,7 @@
30
30
 
31
31
  To be minimally functional, you will almost certainly need to define at least the following settings:
32
32
 
33
- - `settings[:hiera_yaml_file]` as the absolute or relative path to your hiera configuration file
33
+ - `settings[:hiera_config]` as the absolute or relative path to your hiera configuration file
34
34
  - `settings[:hiera_path_strip]` as the prefix to strip when munging the hiera configuration file
35
35
  - `settings[:puppetdb_url]` as the URL to your PuppetDB instance so facts can be obtained
36
36
 
data/doc/optionsref.md CHANGED
@@ -16,6 +16,8 @@ Usage: octocatalog-diff [command line options]
16
16
  --from-catalog FILENAME Use a pre-compiled catalog 'from'
17
17
  --to-catalog FILENAME Use a pre-compiled catalog 'to'
18
18
  --bootstrap-script FILENAME Bootstrap script relative to checkout directory
19
+ --bootstrap-current Run bootstrap script for the current directory too
20
+ --debug-bootstrap Print debugging output for bootstrap script
19
21
  --bootstrap-environment "key1=val1,key2=val2,..."
20
22
  Bootstrap script environment variables in key=value format
21
23
  --bootstrapped-from-dir DIRNAME
@@ -32,13 +34,16 @@ Usage: octocatalog-diff [command line options]
32
34
  More resources to ignore in format type[title]
33
35
  --[no-]include-tags Include changes to tags in the diff output
34
36
  --fact-file FILENAME Fact file to use instead of node lookup
37
+ --cached-master-dir PATH Cache bootstrapped origin/master at this path
35
38
  --master-cache-branch BRANCH Branch to cache
36
39
  --safe-to-delete-cached-master-dir PATH
37
40
  OK to delete cached master directory at this path
38
- --cached-master-dir PATH Cache bootstrapped origin/master at this path
39
41
  --hiera-config PATH Relative path to hiera YAML file
40
42
  --no-hiera-config Disable hiera config file installation
43
+ --hiera-path PATH Path to hiera data directory, relative to top directory of repository
44
+ --no-hiera-path Do not use any default hiera path settings
41
45
  --hiera-path-strip PATH Path prefix to strip when munging hiera.yaml
46
+ --no-hiera-path-strip Do not use any default hiera path strip settings
42
47
  --ignore-attr "attr1,attr2,..."
43
48
  Attributes to ignore
44
49
  --[no-]display-source Show source file and line for each difference
@@ -147,6 +152,19 @@ Usage: octocatalog-diff [command line options]
147
152
  </td>
148
153
  </tr>
149
154
 
155
+ <tr>
156
+ <td valign=top>
157
+ <pre><code>--bootstrap-current </code></pre>
158
+ </td>
159
+ <td valign=top>
160
+ Run bootstrap script for the current directory too
161
+ </td>
162
+ <td valign=top>
163
+ Option to bootstrap the current directory (by default, the bootstrap script is NOT
164
+ run when the catalog builds in the current directory). (<a href="../lib/octocatalog-diff/catalog-diff/cli/options/bootstrap_current.rb">bootstrap_current.rb</a>)
165
+ </td>
166
+ </tr>
167
+
150
168
  <tr>
151
169
  <td valign=top>
152
170
  <pre><code>--bootstrap-environment "key1=val1,key2=val2,..."</code></pre>
@@ -281,6 +299,20 @@ what is most often desired. (<a href="../lib/octocatalog-diff/catalog-diff/cli/o
281
299
  </td>
282
300
  </tr>
283
301
 
302
+ <tr>
303
+ <td valign=top>
304
+ <pre><code>--debug-bootstrap </code></pre>
305
+ </td>
306
+ <td valign=top>
307
+ Print debugging output for bootstrap script
308
+ </td>
309
+ <td valign=top>
310
+ Option to print debugging output for the bootstrap script in addition to the normal
311
+ debugging output. Note that `--debug` must also be enabled for this option to have
312
+ any effect. (<a href="../lib/octocatalog-diff/catalog-diff/cli/options/debug_bootstrap.rb">debug_bootstrap.rb</a>)
313
+ </td>
314
+ </tr>
315
+
284
316
  <tr>
285
317
  <td valign=top>
286
318
  <pre><code>--default-header </code></pre>
@@ -449,6 +481,19 @@ These files must exist and be in Puppet catalog format. (<a href="../lib/octocat
449
481
  </td>
450
482
  </tr>
451
483
 
484
+ <tr>
485
+ <td valign=top>
486
+ <pre><code>--hiera-path PATH</code></pre>
487
+ </td>
488
+ <td valign=top>
489
+ Path to hiera data directory, relative to top directory of repository
490
+ </td>
491
+ <td valign=top>
492
+ Specify the path to the Hiera data directory (relative to the top level Puppet checkout). For Puppet Enterprise and the
493
+ Puppet control repo template, the value of this should be 'hieradata', which is the default. (<a href="../lib/octocatalog-diff/catalog-diff/cli/options/hiera_path.rb">hiera_path.rb</a>)
494
+ </td>
495
+ </tr>
496
+
452
497
  <tr>
453
498
  <td valign=top>
454
499
  <pre><code>--hiera-path-strip PATH</code></pre>
@@ -572,6 +617,31 @@ to ignore any changes for any defined type where this tag is set. (<a href="../l
572
617
  </td>
573
618
  </tr>
574
619
 
620
+ <tr>
621
+ <td valign=top>
622
+ <pre><code>--no-hiera-path </code></pre>
623
+ </td>
624
+ <td valign=top>
625
+ Do not use any default hiera path settings
626
+ </td>
627
+ <td valign=top>
628
+ Specify the path to the Hiera data directory (relative to the top level Puppet checkout). For Puppet Enterprise and the
629
+ Puppet control repo template, the value of this should be 'hieradata', which is the default. (<a href="../lib/octocatalog-diff/catalog-diff/cli/options/hiera_path.rb">hiera_path.rb</a>)
630
+ </td>
631
+ </tr>
632
+
633
+ <tr>
634
+ <td valign=top>
635
+ <pre><code>--no-hiera-path-strip </code></pre>
636
+ </td>
637
+ <td valign=top>
638
+ Do not use any default hiera path strip settings
639
+ </td>
640
+ <td valign=top>
641
+ Specify the path to strip off the datadir to munge hiera.yaml file (<a href="../lib/octocatalog-diff/catalog-diff/cli/options/hiera_path_strip.rb">hiera_path_strip.rb</a>)
642
+ </td>
643
+ </tr>
644
+
575
645
  <tr>
576
646
  <td valign=top>
577
647
  <pre><code>--no-ignore-tags </code></pre>
@@ -39,7 +39,8 @@ module OctocatalogDiff
39
39
  compare_file_text: true,
40
40
  display_datatype_changes: true,
41
41
  parallel: true,
42
- suppress_absent_file_details: true
42
+ suppress_absent_file_details: true,
43
+ hiera_path: 'hieradata'
43
44
  }.freeze
44
45
 
45
46
  # This method is the one to call externally. It is possible to specify alternate
@@ -75,6 +76,8 @@ module OctocatalogDiff
75
76
  # Note: do NOT use 'options[k] ||= v' here because if the value of options[k] is boolean(false)
76
77
  # it will then be overridden. Whereas the intent is to define values only for those keys that don't exist.
77
78
  DEFAULT_OPTIONS.each { |k, v| options[k] = v unless options.key?(k) }
79
+ veto_with_none_options = %w(hiera_path hiera_path_strip)
80
+ veto_with_none_options.each { |x| options.delete(x.to_sym) if options[x.to_sym] == :none }
78
81
 
79
82
  # Fact overrides come in here - 'options' is modified
80
83
  setup_fact_overrides(options)
@@ -0,0 +1,13 @@
1
+ # Option to bootstrap the current directory (by default, the bootstrap script is NOT
2
+ # run when the catalog builds in the current directory).
3
+ # @param parser [OptionParser object] The OptionParser argument
4
+ # @param options [Hash] Options hash being constructed; this is modified in this method.
5
+ OctocatalogDiff::CatalogDiff::Cli::Options::Option.newoption(:bootstrap_current) do
6
+ has_weight 48
7
+
8
+ def parse(parser, options)
9
+ parser.on('--bootstrap-current', 'Run bootstrap script for the current directory too') do
10
+ options[:bootstrap_current] = true
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # Option to print debugging output for the bootstrap script in addition to the normal
2
+ # debugging output. Note that `--debug` must also be enabled for this option to have
3
+ # any effect.
4
+ # @param parser [OptionParser object] The OptionParser argument
5
+ # @param options [Hash] Options hash being constructed; this is modified in this method.
6
+ OctocatalogDiff::CatalogDiff::Cli::Options::Option.newoption(:debug_bootstrap) do
7
+ has_weight 49
8
+
9
+ def parse(parser, options)
10
+ parser.on('--debug-bootstrap', 'Print debugging output for bootstrap script') do
11
+ options[:debug_bootstrap] = true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,36 @@
1
+ # Specify the path to the Hiera data directory (relative to the top level Puppet checkout). For Puppet Enterprise and the
2
+ # Puppet control repo template, the value of this should be 'hieradata', which is the default.
3
+ # @param parser [OptionParser object] The OptionParser argument
4
+ # @param options [Hash] Options hash being constructed; this is modified in this method.
5
+ OctocatalogDiff::CatalogDiff::Cli::Options::Option.newoption(:hiera_path) do
6
+ has_weight 181
7
+
8
+ def parse(parser, options)
9
+ parser.on('--hiera-path PATH', 'Path to hiera data directory, relative to top directory of repository') do |path_in|
10
+ if options.key?(:hiera_path_strip) && options[:hiera_path_strip] != :none
11
+ raise ArgumentError, '--hiera-path and --hiera-path-strip are mutually exclusive'
12
+ end
13
+
14
+ if options[:hiera_path] == :none
15
+ raise ArgumentError, '--hiera-path and --no-hiera-path are mutually exclusive'
16
+ end
17
+
18
+ options[:hiera_path] = path_in
19
+
20
+ if options[:hiera_path].start_with?('/')
21
+ raise ArgumentError, '--hiera-path PATH must be a relative path not an absolute path'
22
+ end
23
+
24
+ options[:hiera_path].sub!(%r{/+$}, '')
25
+ raise ArgumentError, '--hiera-path must not be empty' if options[:hiera_path].empty?
26
+ end
27
+
28
+ parser.on('--no-hiera-path', 'Do not use any default hiera path settings') do
29
+ if options[:hiera_path].is_a?(String)
30
+ raise ArgumentError, '--hiera-path and --no-hiera-path are mutually exclusive'
31
+ end
32
+
33
+ options[:hiera_path] = :none
34
+ end
35
+ end
36
+ end
@@ -2,11 +2,26 @@
2
2
  # @param parser [OptionParser object] The OptionParser argument
3
3
  # @param options [Hash] Options hash being constructed; this is modified in this method.
4
4
  OctocatalogDiff::CatalogDiff::Cli::Options::Option.newoption(:hiera_path_strip) do
5
- has_weight 181
5
+ has_weight 182
6
6
 
7
7
  def parse(parser, options)
8
8
  parser.on('--hiera-path-strip PATH', 'Path prefix to strip when munging hiera.yaml') do |path_in|
9
+ if options.key?(:hiera_path) && options[:hiera_path] != :none
10
+ raise ArgumentError, '--hiera-path and --hiera-path-strip are mutually exclusive'
11
+ end
12
+
13
+ if options[:hiera_path_strip] == :none
14
+ raise ArgumentError, '--hiera-path-strip and --no-hiera-path-strip are mutually exclusive'
15
+ end
16
+
9
17
  options[:hiera_path_strip] = path_in
10
18
  end
19
+
20
+ parser.on('--no-hiera-path-strip', 'Do not use any default hiera path strip settings') do
21
+ if options[:hiera_path_strip].is_a?(String)
22
+ raise ArgumentError, '--hiera-path-strip and --no-hiera-path-strip are mutually exclusive'
23
+ end
24
+ options[:hiera_path_strip] = :none
25
+ end
11
26
  end
12
27
  end
@@ -136,6 +136,10 @@ module OctocatalogDiff
136
136
  def self.run_bootstrap(logger, opts)
137
137
  logger.debug("Begin bootstrap with '#{opts[:bootstrap_script]}' in #{opts[:path]}")
138
138
  result = OctocatalogDiff::Bootstrap.bootstrap(opts)
139
+ if opts[:debug_bootstrap] || result[:status_code] > 0
140
+ output = result[:output].split(/[\r\n]+/)
141
+ output.each { |x| logger.debug("Bootstrap: #{x}") }
142
+ end
139
143
  raise BootstrapError, "bootstrap failed for #{opts[:path]}: #{result[:output]}" unless (result[:status_code]).zero?
140
144
  logger.debug("Success bootstrap in #{opts[:path]}")
141
145
  result[:output]
@@ -27,6 +27,7 @@ module OctocatalogDiff
27
27
  # :enc [String] ENC script file (can be relative or absolute path)
28
28
  # :pe_enc_url [String] ENC URL (for Puppet Enterprise node classification service)
29
29
  # :hiera_config [String] hiera configuration file (relative to base directory)
30
+ # :hiera_path [String] relative path to hiera data files (mutually exclusive with :hiera_path_strip)
30
31
  # :hiera_path_strip [String] string to strip off the beginning of :datadir
31
32
  # :puppetdb_ssl_ca [String] Path to SSL CA certificate
32
33
  # :puppetdb_ssl_client_key [String] String representation of SSL client key
@@ -52,9 +53,8 @@ module OctocatalogDiff
52
53
  install_puppetdb_conf(logger, options[:puppetdb_url], options[:puppetdb_server_url_timeout])
53
54
  install_routes_yaml(logger)
54
55
  end
55
- unless options[:hiera_config].nil?
56
- install_hiera_config(logger, options[:hiera_config], options[:hiera_path_strip])
57
- end
56
+ install_hiera_config(logger, options) unless options[:hiera_config].nil?
57
+
58
58
  @fact_file = install_fact_file(logger, options) if @facts_terminus == 'yaml'
59
59
  @enc = install_enc(logger) unless options[:enc].nil? && options[:pe_enc_url].nil?
60
60
  install_ssl(logger, options) if options[:puppetdb_ssl_ca] || options[:puppetdb_ssl_client_cert]
@@ -179,10 +179,10 @@ module OctocatalogDiff
179
179
  end
180
180
 
181
181
  # Install hiera config file
182
- # @param hiera_config [String] Path to file, relative to checkout
183
- # @param hiera_path_strip [String] Prefix to strip off when munging file
184
- def install_hiera_config(logger, hiera_config, hiera_path_strip)
182
+ # @param options [Hash] Options hash
183
+ def install_hiera_config(logger, options)
185
184
  # Validate hiera config file
185
+ hiera_config = options[:hiera_config]
186
186
  unless hiera_config.is_a?(String)
187
187
  raise ArgumentError, "Called install_hiera_config with a #{hiera_config.class} argument"
188
188
  end
@@ -199,13 +199,23 @@ module OctocatalogDiff
199
199
  obj = YAML.load_file(file_src)
200
200
  %w(yaml json).each do |key|
201
201
  next unless obj.key?(key.to_sym)
202
- next if obj[key.to_sym][:datadir].nil?
203
- unless hiera_path_strip.nil?
204
- rexp1 = Regexp.new('^' + hiera_path_strip)
202
+ if options[:hiera_path_strip].is_a?(String)
203
+ next if obj[key.to_sym][:datadir].nil?
204
+ rexp1 = Regexp.new('^' + options[:hiera_path_strip])
205
205
  obj[key.to_sym][:datadir].sub!(rexp1, @tempdir)
206
+ elsif options[:hiera_path].is_a?(String)
207
+ obj[key.to_sym][:datadir] = File.join(@tempdir, 'environments', 'production', options[:hiera_path])
206
208
  end
207
209
  rexp2 = Regexp.new('%{(::)?environment}')
208
210
  obj[key.to_sym][:datadir].sub!(rexp2, 'production')
211
+
212
+ # Make sure the dirctory exists. If not, log a warning. This is *probably* a setup error, but we don't
213
+ # want it to be fatal in case (for example) someone is doing an octocatalog-diff to verify moving this
214
+ # directory around or even setting up Hiera for the very first time.
215
+ unless File.directory?(obj[key.to_sym][:datadir])
216
+ message = "WARNING: Hiera datadir for #{key} doesn't seem to exist at #{obj[key.to_sym][:datadir]}"
217
+ logger.warn message
218
+ end
209
219
  end
210
220
 
211
221
  # Write properly formatted hiera config file into temporary directory
@@ -97,7 +97,17 @@ module OctocatalogDiff
97
97
  raise Errno::ENOENT, "Invalid dir #{@opts[:bootstrapped_dir]}" unless File.directory?(@opts[:bootstrapped_dir])
98
98
  tmphash[:basedir] = @opts[:bootstrapped_dir]
99
99
  elsif @opts[:branch] == '.'
100
- tmphash[:basedir] = @opts[:basedir]
100
+ if @opts[:bootstrap_current]
101
+ tmphash[:basedir] = Dir.mktmpdir
102
+ at_exit { cleanup_checkout_dir(tmphash[:basedir], logger) }
103
+
104
+ FileUtils.cp_r File.join(@opts[:basedir], '.'), tmphash[:basedir]
105
+
106
+ o = @opts.reject { |k, _v| k == :branch }.merge(path: tmphash[:basedir])
107
+ OctocatalogDiff::CatalogUtil::Bootstrap.bootstrap_directory(o, logger)
108
+ else
109
+ tmphash[:basedir] = @opts[:basedir]
110
+ end
101
111
  else
102
112
  checkout_dir = Dir.mktmpdir
103
113
  at_exit { cleanup_checkout_dir(checkout_dir, logger) }
@@ -15,9 +15,16 @@ module OctocatalogDiff
15
15
  raise ArgumentError, 'Puppet binary was not supplied' if puppet.nil?
16
16
  raise Errno::ENOENT, "Puppet binary #{puppet} doesn't exist" unless File.file?(puppet)
17
17
  cmdline = [Shellwords.escape(puppet), '--version'].join(' ')
18
- output, _code = Open3.capture2e(cmdline)
19
- return Regexp.last_match(1) if output =~ /^([\d\.]+)\s*$/
20
- raise "Unable to determine Puppet version: #{output}"
18
+
19
+ # This is the environment provided to the puppet command.
20
+ env = {
21
+ 'HOME' => ENV['HOME'],
22
+ 'PATH' => ENV['PATH'],
23
+ 'PWD' => File.dirname(puppet)
24
+ }
25
+ out, err, _status = Open3.capture3(env, cmdline, unsetenv_others: true, chdir: env['PWD'])
26
+ return Regexp.last_match(1) if out =~ /^([\d\.]+)\s*$/
27
+ raise "Unable to determine Puppet version: #{out} #{err}"
21
28
  end
22
29
  end
23
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octocatalog-diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub, Inc.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-02 00:00:00.000000000 Z
12
+ date: 2016-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: diffy
@@ -229,6 +229,7 @@ files:
229
229
  - doc/advanced-ci.md
230
230
  - doc/advanced-dynamic-ignores.md
231
231
  - doc/advanced-future-parser.md
232
+ - doc/advanced-hiera-path-stripping.md
232
233
  - doc/advanced-ignores.md
233
234
  - doc/advanced-output-formats.md
234
235
  - doc/advanced-output-hacks.md
@@ -265,6 +266,7 @@ files:
265
266
  - lib/octocatalog-diff/catalog-diff/cli/helpers/fact_override.rb
266
267
  - lib/octocatalog-diff/catalog-diff/cli/options.rb
267
268
  - lib/octocatalog-diff/catalog-diff/cli/options/basedir.rb
269
+ - lib/octocatalog-diff/catalog-diff/cli/options/bootstrap_current.rb
268
270
  - lib/octocatalog-diff/catalog-diff/cli/options/bootstrap_environment.rb
269
271
  - lib/octocatalog-diff/catalog-diff/cli/options/bootstrap_script.rb
270
272
  - lib/octocatalog-diff/catalog-diff/cli/options/bootstrap_then_exit.rb
@@ -274,6 +276,7 @@ files:
274
276
  - lib/octocatalog-diff/catalog-diff/cli/options/color.rb
275
277
  - lib/octocatalog-diff/catalog-diff/cli/options/compare_file_text.rb
276
278
  - lib/octocatalog-diff/catalog-diff/cli/options/debug.rb
279
+ - lib/octocatalog-diff/catalog-diff/cli/options/debug_bootstrap.rb
277
280
  - lib/octocatalog-diff/catalog-diff/cli/options/display_datatype_changes.rb
278
281
  - lib/octocatalog-diff/catalog-diff/cli/options/display_detail_add.rb
279
282
  - lib/octocatalog-diff/catalog-diff/cli/options/display_source_file_line.rb
@@ -285,6 +288,7 @@ files:
285
288
  - lib/octocatalog-diff/catalog-diff/cli/options/from_puppetdb.rb
286
289
  - lib/octocatalog-diff/catalog-diff/cli/options/header.rb
287
290
  - lib/octocatalog-diff/catalog-diff/cli/options/hiera_config.rb
291
+ - lib/octocatalog-diff/catalog-diff/cli/options/hiera_path.rb
288
292
  - lib/octocatalog-diff/catalog-diff/cli/options/hiera_path_strip.rb
289
293
  - lib/octocatalog-diff/catalog-diff/cli/options/hostname.rb
290
294
  - lib/octocatalog-diff/catalog-diff/cli/options/ignore.rb