Skip to content

Commit f22a62e

Browse files
authored
Merge branch 'master' into kpaulisse-puppetdb-v3
2 parents 6949383 + 4aceadc commit f22a62e

13 files changed

Lines changed: 140 additions & 10 deletions

File tree

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.6
1+
0.5.7

doc/advanced-bootstrap.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,28 @@ The [example configuration file](/examples/octocatalog-diff.cfg.rb) contains an
3131
# settings[:bootstrap_script] = '/etc/puppetlabs/repo-bootstrap.sh' # Absolute path
3232
# settings[:bootstrap_script] = 'script/bootstrap' # Relative path
3333
```
34+
35+
## Bootstrap environment
36+
37+
When the bootstrap script runs, a limited set of environment variables are passed from the shell running octocatalog-diff. Only these variables are set:
38+
39+
- `HOME`
40+
- `PATH`
41+
- `PWD` (set to the base directory of your Puppet checkout)
42+
- `BASEDIR` (as explicitly set with `--basedir` CLI option or `settings[:basedir]` setting)
43+
44+
If you wish to set additional environment variables for your bootstrap script, you may do so via the `--bootstrap-environment VAR=value` command line flag, or by defining `settings[:bootstrap_environment] = { 'VAR' => 'value' }` in your configuration file.
45+
46+
As an example, consider that your bootstrap script is written in Python, and needs the `PYTHONPATH` variable set to `/usr/local/lib/python-custom`. Even if this environment variable is set when octocatalog-diff is run, it will not be available to the bootstrap script. You may supply it via the command line:
47+
48+
```
49+
octocatalog-diff --bootstrap-environment PYTHONPATH=/usr/local/lib/python-custom ...
50+
```
51+
52+
Or you may specify it in your configuration file:
53+
54+
```
55+
settings[:bootstrap_environment] = {
56+
'PYTHONPATH' => '/usr/local/lib/python-custom'
57+
}
58+
```

doc/advanced-hiera-path-stripping.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ bin/octocatalog-diff --hiera-config hiera.yaml --hiera-path-strip /etc/puppetlab
3737
:yaml:
3838
:datadir: /var/tmp/puppet-compile-dir-92347829847/environments/%{environment}/hieradata
3939
```
40+
41+
:warning: Be sure that you do NOT include a trailing slash on `--hiera-path-strip` or `settings[:hiera_path_strip]`.

doc/configuration-enc.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,37 @@ For example, when compiling the catalog for `some-node.github.net`, Puppet will
6767
```
6868
6969
Sometimes the ENC script requires credentials or makes other assumptions about the system on which it is running. To be able to run the ENC script on systems other than your Puppet master, you will need to ensure that any such credentials are supplied and other assumptions are met.
70+
71+
## Environment
72+
73+
When the ENC is executed, the following environment variables are set to match the environment of the shell in which octocatalog-diff executes:
74+
75+
- `HOME`
76+
- `PATH`
77+
- `PWD` (set to the temporary directory as previously described)
78+
79+
No other environment variables are passed from the shell. If you wish to pass additional environment variables, you must explicitly list them with the `--pass-env-vars` CLI flag or `settings[:pass_env_vars]` array in your configuration file.
80+
81+
As an example, consider that your ENC is written in Python, and needs the `PYTHONPATH` variable set to `/usr/local/lib/python-custom`. Even if this environment variable is set when octocatalog-diff is run, it will not be available to the ENC script. You may pass the variable via the command line:
82+
83+
```
84+
octocatalog-diff --pass-env-vars PYTHONPATH ...
85+
```
86+
87+
Or you may specify it in your configuration file:
88+
89+
```
90+
settings[:pass_env_vars] = [ 'PYTHONPATH' ]
91+
```
92+
93+
If you wish to specify multiple environment variables to pass:
94+
95+
```
96+
octocatalog-diff --pass-env-vars PYTHONPATH,SECONDVAR,THIRDVAR ...
97+
```
98+
99+
or
100+
101+
```
102+
settings[:pass_env_vars] = [ 'PYTHONPATH', 'SECONDVAR', 'THIRDVAR' ]
103+
```

examples/octocatalog-diff.cfg.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def self.config
5656
# In this case, you desire to strip `/etc/puppetlabs/code` from the beginning of the path,
5757
# in order that octocatalog-diff can find your hiera datafiles in the compilation
5858
# location, which is {temporary directory}/environments/production/hieradata.
59+
# If you use this, be sure that you do NOT include a trailing slash!
5960
#
6061
# More: https://github.com/github/octocatalog-diff/blob/master/doc/configuration-hiera.md
6162
##############################################################################################

lib/octocatalog-diff/catalog-util/builddir.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def install_hiera_config(logger, options)
197197

198198
# Munge datadir in hiera config file
199199
obj = YAML.load_file(file_src)
200-
%w(yaml json).each do |key|
200+
(obj[:backends] || %w(yaml json)).each do |key|
201201
next unless obj.key?(key.to_sym)
202202
if options[:hiera_path_strip].is_a?(String)
203203
next if obj[key.to_sym][:datadir].nil?

lib/octocatalog-diff/catalog/puppetmaster.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,17 @@ def build(logger = Logger.new(StringIO.new))
6868

6969
# Returns a hash of parameters for each supported version of the Puppet Server Catalog API.
7070
# @return [Hash] Hash of parameters
71+
#
72+
# Note: The double escaping of the facts here is implemented to correspond to a long standing
73+
# bug in the Puppet code. See https://github.com/puppetlabs/puppet/pull/1818 and
74+
# https://docs.puppet.com/puppet/latest/http_api/http_catalog.html#parameters for explanation.
7175
def puppet_catalog_api
7276
{
7377
2 => {
7478
url: "https://#{@options[:puppet_master]}/#{@options[:branch]}/catalog/#{@node}",
7579
parameters: {
7680
'facts_format' => 'pson',
77-
'facts' => @facts.fudge_timestamp.without('trusted').to_pson,
81+
'facts' => CGI.escape(@facts.fudge_timestamp.without('trusted').to_pson),
7882
'transaction_uuid' => SecureRandom.uuid
7983
}
8084
},
@@ -83,7 +87,7 @@ def puppet_catalog_api
8387
parameters: {
8488
'environment' => @options[:branch],
8589
'facts_format' => 'pson',
86-
'facts' => @facts.fudge_timestamp.without('trusted').to_pson,
90+
'facts' => CGI.escape(@facts.fudge_timestamp.without('trusted').to_pson),
8791
'transaction_uuid' => SecureRandom.uuid
8892
}
8993
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"apt_update_last_success":1458162123,
3+
"architecture":"amd64",
4+
"datacenter":"xyz",
5+
"fqdn":"rspec-node.xyz.github.net",
6+
"math":"1+2=3",
7+
"percent":"25%20=5",
8+
"_timestamp":"2014-12-02 14:56:20 -0600"
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#--- !ruby/object:Puppet::Node::Facts
2+
name: rspec-node.xyz.github.net
3+
values:
4+
apt_update_last_success: 1458162123
5+
architecture: amd64
6+
datacenter: xyz
7+
fqdn: rspec-node.xyz.github.net
8+
math: "1+2=3"
9+
percent: "25%20=5"
10+
"_timestamp": 2014-12-02 12:56:20.865795 -08:00
11+
expiration: 2014-12-02 13:11:20.521667 -08:00
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
:backends:
3+
- eyaml
4+
- yaml
5+
- json
6+
:yaml:
7+
:datadir: /var/lib/puppet/environments/%{::environment}/hieradata
8+
:eyaml:
9+
:datadir: /var/lib/puppet/environments/%{::environment}/hieradata
10+
:json:
11+
:datadir: /var/lib/puppet/environments/%{::environment}/hieradata
12+
:hierarchy:
13+
- servers/%{::fqdn}
14+
- datacenter/%{::datacenter}
15+
- platform/%{::virtual}
16+
- os/%{::operatingsystem}/%{::lsbdistcodename}
17+
- os/%{::operatingsystem}
18+
- common
19+
:merge_behavior: deeper
20+
:logger: console

0 commit comments

Comments
 (0)