Testing the effect of Puppet stringify_facts with octocatalog-diff

When migrating from Puppet 3 to Puppet 4, the first big step is preparing your Puppet manifests for the differences in facts.

Previously in Puppet, the values of facts used to be all strings. In Puppet 4, facts can have various proper data types like booleans, arrays and hashes. In Puppet 3, you can get the same behavior by setting the option stringify_facts = false on the agents.

Since the facts will be different, your Puppet code might behave differently. Especially in the case of booleans, you might previously have compared against "true", where now it’s true (use any2bool to support both).


To test the effects of the change before potentially breaking configuration, I turned to octocatalog-diff. It’s a tool by GitHub that shows the differences between two Puppet catalogues (the compiled output of your Puppet manifests, representing the configuration that will be applied).

For the following script to work, octocatalog-diff should already be configured with PuppetDB access. For each given host, the script will:

  1. fetch the facts from the host by running Facter over SSH. The JSON output of Facter is unaffected by stringification.
  2. compile two catalogs (from the manifests in the current directory), one with facts from PuppetDB and the other with the fetched facts, and compare them

set -e -u -o pipefail

mkdir -p facts

for hostname in "$@"; do
	echo "${hostname}"
		ssh "${hostname}" sudo facter --json --puppet > "${fact_file}"
		octocatalog-diff --hostname "${hostname}" --to-fact-file "${fact_file}" --from .
	) || true

Now when we execute it, we can see whether our catalogs are ready:

./diff_stringify_facts.sh host1.example.com host2.example.com
I, [2017-09-08T15:34:29.591598 #84032]  INFO -- : Catalogs compiled for host1.example.com
I, [2017-09-08T15:34:29.699115 #84032]  INFO -- : Diffs computed for host1.example.com
I, [2017-09-08T15:34:29.699145 #84032]  INFO -- : No differences
I, [2017-09-08T15:34:29.591598 #84032]  INFO -- : Catalogs compiled for host2.example.com
I, [2017-09-08T15:34:29.699115 #84032]  INFO -- : Diffs computed for host2.example.com
I, [2017-09-08T15:34:29.699145 #84032]  INFO -- : No differences

Looks like we are doing fine 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s