diff --git a/README.md b/README.md index 7cdb01d..767fc80 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ ![Catalog Diff](https://raw.githubusercontent.com/voxpupuli/puppet-catalog_diff/master/catalog-diff.png) -#### Table of Contents +# Table of Contents 1. [Overview](#overview) 1. [Module Description](#module-description) @@ -24,14 +24,20 @@ 1. [Usage](#usage) 1. [Multi threaded compile requests](#multi-threaded-compile-requests) 1. [Fact search](#fact-search) + 1. [Node list](#node-list) 1. [Changed depth](#changed-depth) - 1. [Output report](#output-report) + 1. [Output Report](#output-report) + 1. [Non-default PuppetDB/Configuring PuppetDB](#non-default-puppetdbconfiguring-puppetdb) + 1. [Use without PuppetDB](#use-without-puppetdb) + 1. [Non-default Puppetserver](#non-default-puppetserver) 1. [Limitations](#limitations) 1. [Previous Authors](#previous-authors) 1. [Contributors](#contributors) -1. [See Also](#see-also) +1. [See also](#see-also) 1. [Upload facts to PuppetDB](#upload-facts-to-puppetdb) 1. [Modern fact submission](#modern-fact-submission) + 1. [complex fact submission](#complex-fact-submission) + 1. [Further documentation](#further-documentation) ## Overview @@ -293,6 +299,12 @@ via CLI options Those are: * `--old_puppetdb_tls_key=` * `--old_puppetdb_tls_ca=` +#### Use without PuppetDB + +It is possible to use this module without PuppetDB. +If the libraries for PuppetDB are not installed, the module will set the +puppet_url parameter to `https://puppetdb:8081` and will not use PuppetDB. + ### Non-default Puppetserver `puppet catalog diff` can request an old catalog from a Puppetserver. The diff --git a/lib/puppet/catalog-diff/puppetdbfactory.rb b/lib/puppet/catalog-diff/puppetdbfactory.rb new file mode 100644 index 0000000..3a4537b --- /dev/null +++ b/lib/puppet/catalog-diff/puppetdbfactory.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# Puppet::CatalogDiff +module Puppet::CatalogDiff + class Puppetdbfactory + def self.puppetdb_url + begin + require 'puppet/util/puppetdb' + puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] + rescue LoadError + # PuppetDB is not available, so we can't use it + # This is fine, we can still run the catalog diff without it + puppetdb_url = 'https://puppetdb:8081' + end + puppetdb_url + end + end +end diff --git a/lib/puppet/face/catalog/diff.rb b/lib/puppet/face/catalog/diff.rb index 7663156..ccd167f 100644 --- a/lib/puppet/face/catalog/diff.rb +++ b/lib/puppet/face/catalog/diff.rb @@ -1,6 +1,6 @@ require 'puppet/face' require 'json' -require 'puppet/util/puppetdb' +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'catalog-diff', 'puppetdbfactory.rb')) begin require 'parallel' @@ -13,7 +13,7 @@ action :diff do summary 'Compare catalogs from different puppet versions.' arguments ' ' - puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] + puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url hostcert = Puppet.settings[:hostcert] hostprivkey = Puppet.settings[:hostprivkey] localcacert = Puppet.settings[:localcacert] @@ -136,20 +136,22 @@ Validation Process: - - Grab a catalog from your existing machine running the old version - - Configure your new Puppet master, copy the facts from your old master - to the new one - - Compile the catalog for this host on the new master: + - Grab a catalog from your existing machine running the old version + - Configure your new Puppet master, copy the facts from your old master + to the new one + - Compile the catalog for this host on the new master: - puppet master --compile fqdn > fqdn.pson + puppet master --compile fqdn > fqdn.pson - - Puppet puts a header in some catalogs compiled in this way, remove it if present - - At this point you should have 2 different catalogs. To compare them run: + - Puppet puts a header in some catalogs compiled in this way, remove it if present + - At this point you should have 2 different catalogs. To compare them run: - puppet catalog diff - - Alternatively you can process a directory containing matching files - - i.e. path/to/old/node_name.yaml and path/to/new/node_name.yaml - puppet catalog diff + puppet catalog diff + + - Alternatively you can process a directory containing matching files + - i.e. path/to/old/node_name.yaml and path/to/new/node_name.yaml + + puppet catalog diff This code only validates the catalogs, it cannot tell you if the behavior of the providers that interpret the catalog has changed so testing is still diff --git a/lib/puppet/face/catalog/pull.rb b/lib/puppet/face/catalog/pull.rb index 65aa0b8..594cd1e 100644 --- a/lib/puppet/face/catalog/pull.rb +++ b/lib/puppet/face/catalog/pull.rb @@ -1,12 +1,12 @@ require 'puppet/face' require 'digest' -require 'puppet/util/puppetdb' +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'catalog-diff', 'puppetdbfactory.rb')) Puppet::Face.define(:catalog, '0.0.1') do action :pull do - description 'Pull catalogs from duel puppet masters' + summary 'Pull catalogs from duel puppet masters' arguments '/tmp/old_catalogs /tmp/new_catalogs' - puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] + puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url hostcert = Puppet.settings[:hostcert] hostprivkey = Puppet.settings[:hostprivkey] localcacert = Puppet.settings[:localcacert] diff --git a/lib/puppet/face/catalog/seed.rb b/lib/puppet/face/catalog/seed.rb index 6f5b09a..a278a6b 100644 --- a/lib/puppet/face/catalog/seed.rb +++ b/lib/puppet/face/catalog/seed.rb @@ -1,11 +1,11 @@ require 'puppet/face' -require 'puppet/util/puppetdb' +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'catalog-diff', 'puppetdbfactory.rb')) Puppet::Face.define(:catalog, '0.0.1') do action :seed do summary 'Generate a series of catalogs' arguments ' fact=CaseSensitiveValue' - puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] + puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url hostcert = Puppet.settings[:hostcert] hostprivkey = Puppet.settings[:hostprivkey] localcacert = Puppet.settings[:localcacert]