do X if package Y is installed?

791 views
Skip to first unread message

Bill Weiss

unread,
Jun 1, 2010, 5:31:35 PM6/1/10
to puppet...@googlegroups.com
All,
 
Sorry if this is a FAQ that I’ve missed.  A pointer to TFM would be appreciated if so.
 
I’m looking for a conditional include of sorts.  In module X, I’d like to frob a file if the httpd package is installed.  If it’s not, I want to just skip it.  Is there a simple way to do this?
 
Thanks.
 
--
Bill Weiss
Backstop Solutions Group
 
 
 

Trevor Vaughan

unread,
Jun 1, 2010, 8:30:00 PM6/1/10
to puppet...@googlegroups.com, Bill Weiss
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Your best bet is to write a custom fact that returns the status of httpd
installation.

There is a good tutorial on writing custom facts in the docs.

Trevor

On 06/01/2010 05:31 PM, Bill Weiss wrote:
> All,
>

> Sorry if this is a FAQ that I?ve missed. A pointer to TFM would be
> appreciated if so.
>
> I?m looking for a conditional include of sorts. In module X, I?d like
> to frob a file if the httpd package is installed. If it?s not, I want


> to just skip it. Is there a simple way to do this?
>
> Thanks.
>
> --
> Bill Weiss
> Backstop Solutions Group
>
>
>
>

> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to
> puppet-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.

- --
Trevor Vaughan
Vice President, Onyx Point, Inc.
email: tvau...@onyxpoint.com
phone: 410-541-ONYX (6699)
pgp: 0x6C701E94

- -- This account not approved for unencrypted sensitive information --
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAkwFpggACgkQyWMIJmxwHpQSZgCgziFUAs5QI9V/48XCmQhAU6uw
vHwAnRL61ZihpE3iwvoBk6klOAFOHCGy
=EOK8
-----END PGP SIGNATURE-----

tvaughan.vcf

Daniel Pittman

unread,
Jun 2, 2010, 2:36:01 AM6/2/10
to puppet...@googlegroups.com
Bill Weiss <bwe...@backstopsolutions.com> writes:

> Sorry if this is a FAQ that I’ve missed. A pointer to TFM would be
> appreciated if so.
>
> I’m looking for a conditional include of sorts. In module X, I’d like to
> frob a file if the httpd package is installed. If it’s not, I want to just
> skip it. Is there a simple way to do this?

Other people pointed you to writing a custom fact. Let me instead tell you
why this isn't the best strategy, and suggest another approach that might work
better in the long run:

Generally speaking, the more decisions you make in your code the harder it is
to understand. For example, module foo might do something or might not based
on module bar being included — in this case, module bar is the HTTPD package
being installed.


A better approach, and one that is simpler, is to specify policy:

Any host that needs a web server has httpd installed and this file
frobbed.

Any host that doesn't need a web server does not have httpd installed.

Then, code that up in your manifests without the decision:

In X, install httpd[1] and frob the file. In Y, don't do either.

Daniel

Footnotes:
[1] Probably best done by include a httpd class rather than directly writing
out the 'package' stanza, so other modules can also add the httpd service.

--
✣ Daniel Pittman ✉ dan...@rimspace.net+61 401 155 707
♽ made with 100 percent post-consumer electrons

Bill Weiss

unread,
Jun 24, 2010, 6:03:23 PM6/24/10
to puppet...@googlegroups.com
Sorry for raising my thread from the past here.

My problem is, in this case, there are machines that need X but not Y, Y but not X, X and Y, or neither. I can obviously write all of those cases out separately, but that means duplication of code for setting up the parts of X and Y that aren't dependant.

Custom facts are probably the best way for me to do this, but I'd love to hear that there's a simpler way.

David Schmitt

unread,
Jun 28, 2010, 4:09:40 AM6/28/10
to puppet...@googlegroups.com
On 6/25/2010 12:03 AM, Bill Weiss wrote:
> My problem is, in this case, there are machines that need X but not
> Y, Y but not X, X and Y, or neither. I can obviously write all of
> those cases out separately, but that means duplication of code for
> setting up the parts of X and Y that aren't dependant.
>
> Custom facts are probably the best way for me to do this, but I'd
> love to hear that there's a simpler way.


If you can decide in your node source (site.pp or external) which
components are needed, this is very easy:


node a { include X }
node b { include Y }
node c { include X,Y }
node d { }


If you **cannot** decide in your node source, you're probably doing
something wrong[1] and need to explain your problem better.

Best Regards, David

[1] I know, converting legacy systems is a pain, but IMHO you're still
better off doing a manual survey and nailing it down instead of trying
to make automatic decisions that'll backfire down the road.
--
dasz.at OG Tel: +43 (0)664 2602670 Web: http://dasz.at
Klosterneuburg UID: ATU64260999

FB-Nr.: FN 309285 g FB-Gericht: LG Korneuburg

Reply all
Reply to author
Forward
0 new messages