Run Puppet Class only once

1,147 views
Skip to first unread message

Christoph

unread,
Jun 7, 2016, 6:13:33 AM6/7/16
to Puppet Users
Hi there,

I want to run a whole puppet class only once when provisioning a system for the first time.

Unfortunately I do not find a way to do this.

I know how to run commands once using onlyif or unless or creates, but what about running a whole class ?

Thanks
  Christoph

Gavin Williams

unread,
Jun 7, 2016, 6:38:48 AM6/7/16
to Puppet Users
Christoph

I've done something similar by wrapping the class on a conditional, such as a 'class_ran=true' fact...

That way, the class only gets included in the catalogue if 'class_ran=false'... 

A bit crude, but it works... 

Gav

Rob Nelson

unread,
Jun 7, 2016, 7:52:56 AM6/7/16
to puppet...@googlegroups.com
Puppet doesn't run a class, it applies a manifest. If you apply the manifest once, either with `puppet apply somefile.pp` or `puppet agent -t` without the agent running as a service, your catalog will be applied just once. If you want to keep running puppet in the future, have your node classifier return a different catalog without that class.

But, this kind of defeats the purpose of puppet. It has idempotency, so whether you apply a catalog with that class once or a thousand times, your results should always be the same. If it's not, you may be relying on Execs too much over other resource types that are better suited to your needs.

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/81d340b3-3ea9-4c57-8603-e1d5ba03d860%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan White

unread,
Jun 7, 2016, 7:59:02 AM6/7/16
to puppet...@googlegroups.com
Can you provide more detail on exactly what you want to do ?
A generic how-to request does not work in this instance.
Dan White | d_e_...@icloud.com
------------------------------------------------
“Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”  (Bill Waterson: Calvin & Hobbes)

dkoleary

unread,
Jun 8, 2016, 9:25:03 PM6/8/16
to Puppet Users
Hey;

I don't know if this matches the OP's scenario; but, I've been contemplating something similar during provisioning.  To provide context, as you can probably tell from my other posts, I'm just rolling out puppet server after a long absence and even then wasn't exactly an expert.

Like most places, I imagine, I support a reasonably complex environment... different data centers, different environments, different zones (dmz, zone 1, etc).

Quite a bit of my modules that I'm planning on developing will be based on custom facts such as "$ facter auth" returns ldap, local, poss others if mgmt gets its way, "$ facter dc" returns the name of the datacenter.  

Short version: Those custom facts won't be available to the modules until the agent's been run once.  The "solution" as yet untried is similar to what Rob Nelson suggested ie: have a "build" class(es) that gets applied via the enc that does basic configs, then update the enc with the final config.

I'm certainly open to suggestions if there's a better way.

Thanks

Doug O'Leary

jcbollinger

unread,
Jun 9, 2016, 9:27:18 AM6/9/16
to Puppet Users
As Rob described, what you describe goes against the Puppet grain.  Classes and resources should be idempotent -- that is the purpose of Exec's onlyif, unless, and creates parameters.  Puppet is not a script engine; it is a state management system.

If you insist on writing and applying classes that are not idempotent, however, then your options for controlling whether such classes are applied to a given node on a given run are these:
  1. Assign the class only to nodes to which you want to apply it
That implies that you need a mechanism to determine whether your class needs to be applied; among the more promising of such mechanisms are (i) manipulating node facts and (ii) establishing separate environments within Puppet.  Note also that you must be sure to disable usage of cached catalogs wherever there is any chance that a catalog contains a class that should not be re-applied.


John

Reply all
Reply to author
Forward
0 new messages