Ask Your Question

Package unless

asked 2014-08-11 06:31:24 -0600

DJB gravatar image

Hi Guys,

Simaler to the

exec { 'C:\command.exe':
          unless => 'C:\findstr /C:"SomeString" C:\config.xml',

Is their any way this can be achieved for

package { 'SomePackage':
               ensure => absent,
               unless => 'C:\findstr /C:"SomeString" C:\config.xml',

Using any means other than node classification?

Having a puppet module that assigns a class to a node based on the absence of another class would also work in my situation.

I appreciate any and all feed back,

Kind regards

edit retag flag offensive close merge delete


I should clarify that it is the "unless" condition I am referring too.

DJB gravatar imageDJB ( 2014-08-11 06:37:35 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2014-08-11 08:50:46 -0600

jonuwz gravatar image

updated 2014-08-11 08:51:42 -0600

$xmlconfig = file('C:\config.xml','NUL')

if $xmlconfig !~ /SomeString/ {

  package {'SomePackage':
    ensure => absent,


Should work, thats how its done on linux anyway.

$xmlconfig is set to the contents of c:\config.xml or NUL (Which is guaranteed to exist and contain nothing)
If $xmlconfig doesnt contain 'SomeString' ensure SomePackage is removed

edit flag offensive delete link more


I don't think this will work. The catalog is compile on the master so the file check will never happen on the agent machine.

ramindk gravatar imageramindk ( 2014-08-11 18:02:02 -0600 )edit

Thankyou very much Jonuwz This is perfect. For me though i had to have File['C:\config.xml'] rather than file('C:\config.xml') Not sure why, but it works :)

DJB gravatar imageDJB ( 2014-08-12 03:22:04 -0600 )edit

answered 2014-08-11 14:05:01 -0600

3h4x gravatar image


Jonuwz's answer is good but I think you are doing it the wrong way. Node that you want to change might have or might not have this app so this code is redundant. Your nodes should be architected in a way you know whats inside. In site.pp

node app1, app2, app3 {
  include role::some_app

node proxy1, proxy2 {
  include role::proxy 

In role/some_app.pp

class role::some_app {
  include profile::some_app
  include profile::monitoring
  include profile::security
  include profile::users

And so on in profiles and hiera. So your nodes will have always the same config. If anything happens you can create new VM and spin it up with puppet. Famous quote time "Treat it as cattle not as pets" ;)

To be honest I think puppet is not the best tool to solve this problem. You can use facter or variable but no slick way to do this.

edit flag offensive delete link more


Thank you 3h4x for your time and input. I do really appreciate it. In my situation we have 100's unique package classes that will be applied to nodes or groups of nodes on a case by case basis. For nodes we are talking around 1,000 and they may already have packages installed that should not.

DJB gravatar imageDJB ( 2014-08-12 03:26:08 -0600 )edit

So a common class thats assigned to all nodes that removes packages that have not been assigned to nodes will make for one tenth of the workload and complexity on our part. Each environment is unique and from what I can understand with my knowledge this is the best way to achieve the desired state.

DJB gravatar imageDJB ( 2014-08-12 03:28:07 -0600 )edit

Thank you again

DJB gravatar imageDJB ( 2014-08-12 03:30:45 -0600 )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

1 follower


Asked: 2014-08-11 06:31:24 -0600

Seen: 667 times

Last updated: Aug 11 '14