0

I'm downloading a RPM using wget and I want to check if the package is installed before I download it. I'm not using a RPM repo, so I can't just do

package { ...
  ensure => installed
}

How can I do something like:

if HOW_TO_CHECK_IF_PACKAGE_X_IS_INSTALLED
   ... do wget etc.

Before someone asks, this didn't work for me: Puppet - test if a package already defined?

Community
  • 1
  • 1
user278530
  • 83
  • 2
  • 11
  • 2
    I used custom facters before to check e.g. if a file exists so I've got the feeling I need custom facter for this one too I just don't know how to write it – user278530 Jul 08 '15 at 18:16
  • Yes, but nitpick: Those are called *facts*. The tool itself is named *Facter* but each item is referred to as a *fact*. – Felix Frank Jul 09 '15 at 09:01

2 Answers2

3

If you're downloading an RPM and installing it, you could do so like this:

package { 'foo':
  ensure   => installed,
  provider => 'rpm',
  source   => 'http://example.com/foo.rpm',
}
Peter Souter
  • 5,110
  • 1
  • 33
  • 62
0

The solution was a custom facter:

require"puppet"
module Puppet::Parser::Functions
  newfunction(:package_installed, :type => :rvalue) do |args|
    packageName = args[0]
    return system "rpm --quiet -q #{packageName}"
  end
end
user278530
  • 83
  • 2
  • 11
  • 5
    Dude this is **not** a custom fact. It's a parser function that is run *on the master* and queries packages that are installed *on the master machine*. If you are using `puppet apply` this just happens to work, but is not a solution really. – Felix Frank Jul 09 '15 at 08:59
  • 1
    Indeed, if you want a fact to get the package installation status, you should do something like the edit I just made – Peter Souter Jul 09 '15 at 10:38