1

I am new to Puppet, and I am trying to install a file if a package is installed. So in pseudocode:

IF postfix is installed DO
  touch /tmp/wehavepostfix
DONE

I can do something like:

file { '/tmp/wehavepostfix':
  ensure => file,
  content => "foobar",
  require => Package['postfix'],
}

However, this requires something like:

package { 'postfix':
  ensure => installed,
}

Now, the issue I am facing is that I do not want to install Postfix. So I dont want to set "ensure => installed". However, I do not want to uninstall it when it is installed either.

Basically, I want Puppet to do nothing with the package, but I do want to be able to check whether it is installed or not.

I am aware that I can install custom Facters. However, I think this is such a basic check that I can hardly believe this has to be done with a facter.

Rudy Broersma
  • 227
  • 1
  • 4
  • 7

2 Answers2

2

At first you have to understand that Puppet is designed to describe final state of resources. Because of that, it is rather difficult to define something like "do nothing with the package". It is not proper way of using Puppet.

Additionally line require => Package['postfix'], doesn't mean, create file if package exist. It means apply a File['/tmp/wehavepostfix'] resource after Package['postfix'] resource. Here is more about relationships and ordering in Puppet.

For such conditional situations, facter facts are best. Just define your custom facter fact e.g $package_postfix_exist, and next use it in your Puppet manifest e.g.

if $package_postfix_exist == 'true' {
    file { '/tmp/wehavepostfix':
        ensure => file,
        content => "foobar",
    }
}
kkamil
  • 2,593
  • 11
  • 21
0

I know this is an old question.. I had to dig around quite a bit to get this working for me.. something like this will get you what you need. (assuming you have enabled package collection in your console.

Checks if the package is installed. and lets you do other things. (even if you do not control that package within puppet.

  $facts['_puppet_inventory_1']['packages'].each |$packagename|
     {
     if $packagename[0] == 'service/network/samba'
        {
             Do.. stuff...

         break
         }
      }
Rat
  • 1