Ask Your Question
0

How do I make sure a package is only installed on specific clients/machines?

asked 2016-06-09 12:22:52 -0500

priki gravatar image

I want to make sure certain packages(e.g. gcc and/or x11) are only installed on specific machines.

With my limited experience with puppet, I came up with this:

site.pp

package { 'gcc': ensure => 'absent', }

nodes.pp

node 'linuxtest.host.org' { package { 'gcc' : ensure => 'present', } }

Of course it would end up not working since the resource is already declared twice.

Could anyone help me out on how to go about getting this to work? Thanks in advance!

edit retag flag offensive close merge delete

Comments

If you want GCC installed only a few machines, why not just take the package resources out of 'site.pp' and use the code in 'nodes.pp'?

bschonecker gravatar imagebschonecker ( 2016-06-10 11:33:36 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-06-09 23:08:49 -0500

virtblackbelt gravatar image

Two options, one more "blessed" by the style guides than the other. To me, they both seem fairly similar in their output, but the approved way looks ugly to me and the non-approved way seems easier. In both cases, you don't do the package definition at the global level, you include it within something else.

The approved way is to create a base class that is included in all servers and then use a resource collector to "tag" the resource you want to modify:

class { 'base':
      package { 'gcc':
          ensure => absent,
      }
}

node 'normal' {
      class { 'base': }   # or "include base"
}

node 'testlinux' {
      class { 'base': }
      Package <| tag == 'gcc' |> { ensure => 'present' }
}

The less approved way is to use inheritance to define a baseline node where you set all your common elements. All your nodes inherit that baseline, then you can easily override resource declarations in individual nodes that require it. Most of your nodes will have a simple "inherits 'baseline'" definition, but your special nodes will need to override the resource declaration.

node 'baseline' {
     package {'gcc':
          ensure => 'absent'
     }
}

node 'regularserver' inherits 'baseline' {
       # nothing to do, everything happens in 'baseline'
}

node 'linuxtest' inherits 'baseline' {
    Package['gcc'] { ensure => 'present' }
}

This way looks cleaner to me. Using resource collectors and tags seems like a kludge. But the style guides say that inheritance is generally a more complex way than is needed.

edit flag offensive delete link more

Comments

Thank you very much! This is what I was looking for. Your post just taught me much of what I need to know about resource collectors too.

priki gravatar imagepriki ( 2016-06-13 15:15:36 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2016-06-09 12:22:52 -0500

Seen: 52 times

Last updated: Jun 09 '16