Skip to content

Commit

Permalink
Merge pull request #10 from github/kpaulisse-puppetdb-termini
Browse files Browse the repository at this point in the history
Remove dependency on puppetdb-terminus if storeconfigs is not used
  • Loading branch information
kpaulisse committed Nov 2, 2016
2 parents 5b6131e + 5b18543 commit 83fc87e
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .version
@@ -1 +1 @@
0.5.1
0.5.3
7 changes: 7 additions & 0 deletions doc/CHANGELOG.md
@@ -0,0 +1,7 @@
# octocatalog-diff change log

| Version | Date | Description / Changes |
| ------- | ---- | ----------- |
| 0.5.3 | 2016-10-31 | https://github.com/github/octocatalog-diff/pull/10: facts terminus optimization |
| 0.5.2 | - | Unreleased internal version |
| 0.5.1 | 2016-10-20 | Initial release |
36 changes: 36 additions & 0 deletions doc/configuration-puppet.md
@@ -0,0 +1,36 @@
# Configuring octocatalog-diff to use Puppet

The most common use of `octocatalog-diff` is to use `puppet` locally to compile catalogs.

In order to successfully use Puppet to compile catalogs:

0. Puppet must be installed on the system.

It is the goal of `octocatalog-diff` to support Puppet version 3.8 and higher, installed via any means supported by Puppet. This includes the [All-In-One agent package](https://docs.puppet.com/puppet/4.0/reference/release_notes.html#all-in-one-packaging) or installed as a Ruby gem.

By default, `octocatalog-diff` will look for the Puppet binary in several common system locations.

For maximum reliability, you can specify the full path to the Puppet binary in the configuration file. For example:

```
##############################################################################################
# puppet_binary
# This is the full path to the puppet binary on your system. If you don't specify this,
# the tool will just run 'puppet' and hope to find it in your path.
##############################################################################################
# settings[:puppet_binary] = '/usr/bin/puppet'
settings[:puppet_binary] = '/opt/puppetlabs/puppet/bin/puppet'
```

0. Applies if you are using [exported resources](https://docs.puppet.com/puppet/latest/reference/lang_exported.html) from PuppetDB (i.e., the octocatalog-diff `--storeconfigs` option enabled):

Your Puppet installation must have the `puppetdb-termini` feature available. This feature may not be included by default with the Puppet agent package.

Consult the [Connecting Puppet masters to PuppetDB](https://docs.puppet.com/puppetdb/latest/connect_puppet_master.html#step-1-install-plug-ins) documentation for instructions on installing the `puppetdb-termini` gem.

:warning: Attention Mac OS users: the [documentation](https://docs.puppet.com/puppet/latest/reference/puppet_collections.html#os-x-systems) states:

> While the puppet-agent package is the only component of a Puppet Collection available on OS X, you can still use Puppet Collections to ensure the version of package-agent you install is compatible with the Puppet Collection powering your infrastructure.
Unfortunately this means that you won't be able to enable `--storeconfigs` with the All-In-One Puppet Agent on Mac OS X, unless you manually install a gem-packaged version of `puppetdb-terminus`. The procedure for this is beyond the scope of this documentation.
1 change: 1 addition & 0 deletions doc/configuration.md
Expand Up @@ -39,6 +39,7 @@
- [Configuring octocatalog-diff to use Hiera](/doc/configuration-hiera.md)
- [Configuring octocatalog-diff to use ENC](/doc/configuration-enc.md)
- [Configuring octocatalog-diff to use PuppetDB](/doc/configuration-puppetdb.md)
- [Configuring octocatalog-diff to use Puppet](/doc/configuration-puppet.md)

0. Test the configuration, which will indicate the location of the configuration file and validate the contents thereof.

Expand Down
13 changes: 13 additions & 0 deletions examples/octocatalog-diff.cfg.rb
Expand Up @@ -158,6 +158,19 @@ def self.config
# the tool will just run 'puppet' and hope to find it in your path.
##############################################################################################

# These are some common defaults. We recommend removing this and setting explicitly below.
puppet_may_be_in = %w(
bin/puppet
/opt/puppetlabs/puppet/bin/puppet
/usr/bin/puppet
/usr/local/bin/puppet
)
puppet_may_be_in.each do |path|
next unless File.executable?(path)
settings[:puppet_binary] = path
break
end

# settings[:puppet_binary] = '/usr/bin/puppet'
# settings[:puppet_binary] = '/opt/puppetlabs/puppet/bin/puppet'

Expand Down
9 changes: 5 additions & 4 deletions lib/octocatalog-diff/catalog-util/builddir.rb
Expand Up @@ -42,6 +42,7 @@ def initialize(options = {}, logger = nil)
@enc = nil
@fact_file = nil
@node = options[:node]
@facts_terminus = options.fetch(:facts_terminus, 'yaml')

create_structure
install_directory_symlink(logger, options[:basedir])
Expand All @@ -54,7 +55,7 @@ def initialize(options = {}, logger = nil)
unless options[:hiera_config].nil?
install_hiera_config(logger, options[:hiera_config], options[:hiera_path_strip])
end
@fact_file = install_fact_file(logger, options) unless options.fetch(:facts_terminus, 'yaml') != 'yaml'
@fact_file = install_fact_file(logger, options) if @facts_terminus == 'yaml'
@enc = install_enc(logger) unless options[:enc].nil? && options[:pe_enc_url].nil?
install_ssl(logger, options) if options[:puppetdb_ssl_ca] || options[:puppetdb_ssl_client_cert]
end
Expand Down Expand Up @@ -98,7 +99,7 @@ def install_routes_yaml(logger)
routes_hash = {
'master' => {
'facts' => {
'terminus' => 'puppetdb',
'terminus' => @facts_terminus,
'cache' => 'yaml'
},
'catalog' => {
Expand All @@ -113,8 +114,8 @@ def install_routes_yaml(logger)
# Install the fact file in temporary directory
# @param options [Hash] Options
def install_fact_file(logger, options)
unless options[:facts_terminus].nil? || options[:facts_terminus] == 'yaml'
raise ArgumentError, "Called install_fact_file but :facts_terminus = #{options[:facts_terminus]}"
unless @facts_terminus == 'yaml'
raise ArgumentError, "Called install_fact_file but :facts_terminus = #{@facts_terminus}"
end
unless options[:node].is_a?(String) && !options[:node].empty?
raise ArgumentError, 'Called install_fact_file without node, or with an empty node'
Expand Down
11 changes: 7 additions & 4 deletions lib/octocatalog-diff/catalog/computed.rb
Expand Up @@ -44,6 +44,7 @@ def initialize(options)
@puppet_command = options[:puppet_command]
@retries = nil
@builddir = nil
@facts_terminus = options.fetch(:facts_terminus, 'yaml')

# Pass through the input for other access
@opts = options
Expand All @@ -52,10 +53,12 @@ def initialize(options)

# Actually build the catalog (populate @error_message, @catalog, @catalog_json)
def build(logger = Logger.new(StringIO.new))
facts_obj = OctocatalogDiff::CatalogUtil::Facts.new(@opts, logger)
logger.debug "Start retrieving facts for #{@node} from #{self.class}"
@opts[:facts] = facts_obj.facts
logger.debug "Success retrieving facts for #{@node} from #{self.class}"
if @facts_terminus != 'facter'
facts_obj = OctocatalogDiff::CatalogUtil::Facts.new(@opts, logger)
logger.debug "Start retrieving facts for #{@node} from #{self.class}"
@opts[:facts] = facts_obj.facts
logger.debug "Success retrieving facts for #{@node} from #{self.class}"
end
build_catalog(logger)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/octocatalog-diff/tests/catalog-util/builddir_spec.rb
Expand Up @@ -116,7 +116,7 @@
expect(content.size).to eq(7)
routes_yaml = YAML.load_file(File.join(testobj.tempdir, 'routes.yaml'))
expect(routes_yaml).to eq('master' => {
'facts' => { 'terminus' => 'puppetdb', 'cache' => 'yaml' },
'facts' => { 'terminus' => 'facter', 'cache' => 'yaml' },
'catalog' => { 'cache' => 'json' }
})
end
Expand Down

0 comments on commit 83fc87e

Please sign in to comment.