Python – How To Tell Puppet To Only Install Using Pip If A File Doesn’t Exist

graphitepippuppetpython

I am using Puppet to install some Python packages using pip. I'm using Puppet 2.7, so my package declarations look something like this:

package { "carbon": 
    require => Class["graphite::prereqs::install"],
    ensure  => latest,
    provider => pip,
}

The problem is that this package and the graphite-web package both seem to have a bug that makes it possible to install the same version multiple times using pip. So if I type in sudo pip install carbon multiple times, pip will install it every time. I believ this is a bug with the packages.

This bug seems to confuse Puppet too, because every time I provision my system, carbon and graphite-web are re-installed.

I'm therefore wondering if there's a way to work around this apparent packaging bug. I've tried the following:

package { "carbon": 
    require => Class["graphite::prereqs::install"],
    ensure  => latest,
    provider => pip,
    creates => "/opt/graphite/bin/carbon-cache.py",
}

…but I can't use creates. Is there another way I can tell the package declaration to look for a file before installing the package?

Best Answer

Might want to use exec's creates parameter:

exec { "carbon":
    command => "pip install carbon",
    require => Class["graphite::prereqs::install"],
    creates => "/opt/graphite/bin/carbon-cache.py",
    path    => ["/usr/bin", "/usr/sbin"],
    timeout => 100,
  }