A collection of task oriented solutions in Puppet

 

Deprecate puppet code

Challenge

You want to deprecate puppet code

Solution

Install the deprecate module from the Puppetforge and then

class deprecated_resources {

  # shows a warning in puppetservers log
  # but nothing is shown on the client
  deprecate('2018-01-20', 'Remove Foo at the end of the contract')

  # fail the run and shows a warning in both
  # the clients output and masters logfile
  deprecate('2018-01-25', 'Replace with upstream module', true)

}

Explanation

Once you've been managing your infrastructure for a while it's natural to want to remove or retire parts of your code. You may want to ensure you're reminded to remove users or mark a module as needing an upgrade or replacement from a certain date. While puppet doesn't have any native functionality for this you can pull in one possible solution from the forge.

First install the deanwilson-deprecate module from the Puppetforge.

puppet module install deanwilson-deprecate

Notice: Downloading from https://forgeapi.puppet.com ...
/etc/puppetlabs/code/environments/production/modules
|----deanwilson-deprecate (v0.0.2)

This module provides a single function that you can call from any of your puppet classes. It's invoked with three arguments, the expiry date (in either YYYYMMDD or YYYY-MM-DD formats), a description for the expiry ("remove contractor users") and an optional boolean to indicate if the puppet run should be aborted once the expiration date has passed.

class deprecated_resources {

  # shows a warning in puppetservers log
  # but nothing is shown on the client
  deprecate('2018-01-20', 'Remove Foo at the end of the contract')

  # fail the run and shows a warning in both
  # the clients output and masters logfile
  deprecate('2018-01-25', 'Replace with upstream module', true)

}

If you don't terminate client runs after the deprecation date has occurred you'll need a way to check for expired resources in your puppetserver logs. You will save a lot of time by adding a consistent, easy to search for, string at the start of all your deprecation messages.

See also