Distinguishing between regular and one-time invocations in Puppet code

Can a Puppet script find out whether it was invoked as part of regular configuration run, i.e. a Puppet agent applying configurations at regular intervals (i.e. puppet agent), or because of one-time actions (e.g. puppet agent -t, puppet apply)?

1 answer

  • answered 2017-10-12 06:58 rookie09

    I have not tried this yet in practice, but the following may allow a way forward:

    Settings on the command line (such as --test) are also available as Puppet master variables (such as $settings::test).

    The Puppet master variable $servername identifies the Puppet master for puppet agent runs and is (perhaps) undef for puppet apply runs.

    Hence a recipe for an overall solution may look as follows:

    $onetime = $settings::test or $settings::onetime or ($servername == undef)