0
votes

I am learning Puppet and have taken their "Getting Started with Puppet" class but it did not cover Run Stages, and their documentation on Run Stages is thin.

I need to make sure that two things happen before anything else that Puppet does. I have been advised by the instructor of my "Getting Started with Puppet" class to look at Run Stages.

In my investigation of Run Stages, I have learned that the puppetlabs-stdlib class sets up some "standard" Run Stages. One of them being "setup". As shown in the snippet below I have implemented the stage => 'setup' as per https://puppet.com/docs/puppet/5.5/lang_run_stages.html. However, I am getting errors from Puppet:

root@server:~# puppet agent -t
Info: Using configured environment 'dev_branch'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: 
Server Error: Evaluation Error: Error while evaluating a Resource Statement, Could not find stage setup specified by 
Class[Vpn::Roles::Vpn::Client] (file: 

/etc/puppetlabs/code/environments/wal_prod1910_dev/modules/bh/manifests/roles/snaplocker.pp, line: 5, column: 3) on node server Warning: Not using cache on failed catalog Error: Could not retrieve catalog; skipping run

Looking at the error message and the Puppet documentation, I have added quotations around the various string values and replaced my initial -> with the correct =>, but I still get the same error.

class bh::roles::snaplocker()
{
  # stage => setup takes advantage of the setup run stage introduced by
  #  puppetlabs-stdlib which is pulled in by puppet-control-bh/Puppetfile
  class { 'vpn::roles::vpn::client': stage => 'setup' }

  class { 'bh::profiles::move_archives': stage => 'setup' }

  #...
}

Looking more closely at the error message, I believe that the cause is that puppetlabs-stdlib id introduced by the Puppetfile in the class that calls the module that I am working on. I have been deliberately avoiding trying to pull in puppetlabs-stdlib in the class I am working on to avoid duplication. But apparently I need it... The module I am working on does not have a Puppetfile do I need to somehow include puppetlabs-stdlib in my sub module? If so how should I do that? If not, how to I tell my sub module to use the instance declared in the parent module's Puppetfile?

1
Did you declare the stages you are assigning (as documented at: puppet.com/docs/puppet/5.5/lang_run_stages.html#custom-stages)? main is the only stage that exists by default if I recall correctly. - Matt Schuchard
In trying to understand the project that I inherited I noticed that in the top level module the Puppetfile pulls in puppetlabs-stdlib and in investigating that I noticed that it contains a stages.pp file that defines the setup stage and assumed that I could use that. - cptully
@cptully, it is very important to understand the difference between an installed module making classes available to you on one hand and actually using those classes in your manifests on the other. This is fundamental to how Puppet enables you to configure different machines differently. - John Bollinger

1 Answers

2
votes

Usually, you don't need any stage if you have correct classes/resources dependencies.

From the "Run stages" documentation:

CAUTION: Due to these limitations, use stages with the simplest of classes, and only when absolutely necessary. A valid use case is mass dependencies like package repositories.

In your case, if you really want stages, you should add include stdlib::stages1 or explicitly add stage like stage { 'setup': }