Selectively Install Packages

37 views
Skip to first unread message

Steve Harp

unread,
Mar 4, 2015, 9:57:18 AM3/4/15
to puppet...@googlegroups.com
Hi Guys,

I'm using Puppet for many configuration items and package deployments.  I need to be able to only deploy certain packages/classes when the Agent sends a definable command line option.  

Example: puppet agent --onetime --no-daemonize --verbose --do_something_special

I want to be able to execute a class only when the '--do_something_special' flag is passed.

Is this possible?

Thanks for any suggestions.....

Martin Alfke

unread,
Mar 4, 2015, 10:05:34 AM3/4/15
to puppet...@googlegroups.com
Hi,
On 04 Mar 2015, at 15:57, Steve Harp <steve...@rdasys.com> wrote:

> Hi Guys,
>
> I'm using Puppet for many configuration items and package deployments. I need to be able to only deploy certain packages/classes when the Agent sends a definable command line option.
>
> Example: puppet agent --onetime --no-daemonize --verbose --do_something_special
>
> I want to be able to execute a class only when the '--do_something_special' flag is passed.

You can use the —tag option to only do what is mentioned in a specific class.

e.g. puppet agent —test —tags apache

Classes will become tags automatically.
Besides this you can use the tag metaparameter on the package resource.

hth,

Martin

Steve Harp

unread,
Mar 4, 2015, 11:12:14 AM3/4/15
to puppet...@googlegroups.com
Thanks Martin.

I've tried adding a tag 'testing' to a class and the class deploys regardless of the '--tags testing' being on the puppet agent command line or not.  What am I missing?  I need the class to deploy if and only if specified.

Thanks...

Martin Alfke

unread,
Mar 4, 2015, 11:22:45 AM3/4/15
to puppet...@googlegroups.com
Hi Steve,

with tags you only can execute classes which are enabled anyway.
It is a way to limit execution on a certain subset of classes.

What else:
you can provide a fact at CLI and react on that specific fact:

FACTER_runnow=true puppet agent —test —tags <class>

Inside your class you will do something like

class foo {
if $::runnow {
notify { ‘Only when run now is set’: }
> --
> 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/2a49081b-bd40-440b-aa86-4937354012de%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Garrett Honeycutt

unread,
Mar 4, 2015, 12:25:30 PM3/4/15
to puppet...@googlegroups.com
Hi,

It is possible and pretty straight forward if you use a master-less
setup. In that case you run `puppet apply -v some_manifest.pp`.

From what you are describing it seems that you want to use Puppet as a
method for invoking scripts in an ad-hoc fashion, which is not at all
what Puppet is really built to do. With a configuration management tool,
you want to build a model (aka desired system state) and then apply that
model to your systems.

If your goal is to simply install different packages, first figure out
what your criteria is. Is it based on the role of the system, the OS,
its location, ... ? With that information, you could add the appropriate
levels to Hiera's[1] lookup hierarchy and do your modeling there.

Here's a module[2] that would let you do that.

[1] - https://docs.puppetlabs.com/hiera/1/complete_example.html
[2] - https://forge.puppetlabs.com/ghoneycutt/types#package

Best regards,
-g

--
Garrett Honeycutt
@learnpuppet
Puppet Training with LearnPuppet.com
Mobile: +1.206.414.8658

Steve Harp

unread,
Mar 4, 2015, 3:23:36 PM3/4/15
to puppet...@googlegroups.com
A custom fact worked perfectly.

Thanks very much.....
Reply all
Reply to author
Forward
0 new messages