Skip to content

Commit 8b53370

Browse files
authored
make puppetdb-termini optional (#132)
* Optional * Using a factory for puppetdb_url * Avoid help error pull undocumented action * Add class param to puppetdbfactory to check if the lib was loaded. * Fix indenting in notes * RuboCop does NOT like class vatriables. * Do not use parentheses for method calls with no arguments. * Fix another doc inconsitency * Add entry to readme about use without PuppetDB * Fix TOC * Add entry to readme about use without PuppetDB
1 parent 90f224c commit 8b53370

File tree

5 files changed

+53
-21
lines changed

5 files changed

+53
-21
lines changed

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
![Catalog Diff](https://raw.githubusercontent.com/voxpupuli/puppet-catalog_diff/master/catalog-diff.png)
1515

1616

17-
#### Table of Contents
17+
# Table of Contents
1818

1919
1. [Overview](#overview)
2020
1. [Module Description](#module-description)
@@ -24,14 +24,20 @@
2424
1. [Usage](#usage)
2525
1. [Multi threaded compile requests](#multi-threaded-compile-requests)
2626
1. [Fact search](#fact-search)
27+
1. [Node list](#node-list)
2728
1. [Changed depth](#changed-depth)
28-
1. [Output report](#output-report)
29+
1. [Output Report](#output-report)
30+
1. [Non-default PuppetDB/Configuring PuppetDB](#non-default-puppetdbconfiguring-puppetdb)
31+
1. [Use without PuppetDB](#use-without-puppetdb)
32+
1. [Non-default Puppetserver](#non-default-puppetserver)
2933
1. [Limitations](#limitations)
3034
1. [Previous Authors](#previous-authors)
3135
1. [Contributors](#contributors)
32-
1. [See Also](#see-also)
36+
1. [See also](#see-also)
3337
1. [Upload facts to PuppetDB](#upload-facts-to-puppetdb)
3438
1. [Modern fact submission](#modern-fact-submission)
39+
1. [complex fact submission](#complex-fact-submission)
40+
1. [Further documentation](#further-documentation)
3541

3642

3743
## Overview
@@ -293,6 +299,12 @@ via CLI options Those are:
293299
* `--old_puppetdb_tls_key=`
294300
* `--old_puppetdb_tls_ca=`
295301

302+
#### Use without PuppetDB
303+
304+
It is possible to use this module without PuppetDB.
305+
If the libraries for PuppetDB are not installed, the module will set the
306+
puppet_url parameter to `https://puppetdb:8081` and will not use PuppetDB.
307+
296308
### Non-default Puppetserver
297309

298310
`puppet catalog diff` can request an old catalog from a Puppetserver. The
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
# Puppet::CatalogDiff
4+
module Puppet::CatalogDiff
5+
class Puppetdbfactory
6+
def self.puppetdb_url
7+
begin
8+
require 'puppet/util/puppetdb'
9+
puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0]
10+
rescue LoadError
11+
# PuppetDB is not available, so we can't use it
12+
# This is fine, we can still run the catalog diff without it
13+
puppetdb_url = 'https://puppetdb:8081'
14+
end
15+
puppetdb_url
16+
end
17+
end
18+
end

lib/puppet/face/catalog/diff.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'puppet/face'
22
require 'json'
3-
require 'puppet/util/puppetdb'
3+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'catalog-diff', 'puppetdbfactory.rb'))
44

55
begin
66
require 'parallel'
@@ -13,7 +13,7 @@
1313
action :diff do
1414
summary 'Compare catalogs from different puppet versions.'
1515
arguments '<catalog1> <catalog2>'
16-
puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0]
16+
puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url
1717
hostcert = Puppet.settings[:hostcert]
1818
hostprivkey = Puppet.settings[:hostprivkey]
1919
localcacert = Puppet.settings[:localcacert]
@@ -136,20 +136,22 @@
136136
137137
Validation Process:
138138
139-
- Grab a catalog from your existing machine running the old version
140-
- Configure your new Puppet master, copy the facts from your old master
141-
to the new one
142-
- Compile the catalog for this host on the new master:
139+
- Grab a catalog from your existing machine running the old version
140+
- Configure your new Puppet master, copy the facts from your old master
141+
to the new one
142+
- Compile the catalog for this host on the new master:
143143
144-
puppet master --compile fqdn > fqdn.pson
144+
puppet master --compile fqdn > fqdn.pson
145145
146-
- Puppet puts a header in some catalogs compiled in this way, remove it if present
147-
- At this point you should have 2 different catalogs. To compare them run:
146+
- Puppet puts a header in some catalogs compiled in this way, remove it if present
147+
- At this point you should have 2 different catalogs. To compare them run:
148148
149-
puppet catalog diff <catalog1> <catalog2>
150-
- Alternatively you can process a directory containing matching files
151-
- i.e. path/to/old/node_name.yaml and path/to/new/node_name.yaml
152-
puppet catalog diff <path/to/old> <path/to/new>
149+
puppet catalog diff <catalog1> <catalog2>
150+
151+
- Alternatively you can process a directory containing matching files
152+
- i.e. path/to/old/node_name.yaml and path/to/new/node_name.yaml
153+
154+
puppet catalog diff <path/to/old> <path/to/new>
153155
154156
This code only validates the catalogs, it cannot tell you if the behavior of
155157
the providers that interpret the catalog has changed so testing is still

lib/puppet/face/catalog/pull.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
require 'puppet/face'
22
require 'digest'
3-
require 'puppet/util/puppetdb'
3+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'catalog-diff', 'puppetdbfactory.rb'))
44

55
Puppet::Face.define(:catalog, '0.0.1') do
66
action :pull do
7-
description 'Pull catalogs from duel puppet masters'
7+
summary 'Pull catalogs from duel puppet masters'
88
arguments '/tmp/old_catalogs /tmp/new_catalogs'
9-
puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0]
9+
puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url
1010
hostcert = Puppet.settings[:hostcert]
1111
hostprivkey = Puppet.settings[:hostprivkey]
1212
localcacert = Puppet.settings[:localcacert]

lib/puppet/face/catalog/seed.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
require 'puppet/face'
2-
require 'puppet/util/puppetdb'
2+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'catalog-diff', 'puppetdbfactory.rb'))
33

44
Puppet::Face.define(:catalog, '0.0.1') do
55
action :seed do
66
summary 'Generate a series of catalogs'
77
arguments '<path/to/seed/directory> fact=CaseSensitiveValue'
8-
puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0]
8+
puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url
99
hostcert = Puppet.settings[:hostcert]
1010
hostprivkey = Puppet.settings[:hostprivkey]
1111
localcacert = Puppet.settings[:localcacert]

0 commit comments

Comments
 (0)