How To Tell Puppet To Only Install Using Pip If A File Doesn't Exist
Solution 1
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,
}
Solution 2
I'd try using "ensure => installed" instead of "ensure => latest".
From the puppet type reference:
What state the package should be in. On packaging systems that can retrieve new packages on their own, you can choose which package to retrieve by specifying a version number or latest as the ensure value. On packaging systems that manage configuration files separately from “normal” system files, you can uninstall config files by specifying purged as the ensure value. Valid values are present (also called installed), absent, purged, held, latest. Values can match /./.
I don't know how the pip provider is written, but I bet that if you use installed
instead of latest
, puppet will detect that the package is already installed and not try to install it again.
Solution 3
I haven't tested but try this:
file { "/opt/graphite/bin/carbon-cache.py":
ensure => 'absent',
}
package { "carbon":
require => [ Class["graphite::prereqs::install"],
File["/opt/graphite/bin/carbon-cache.py"]
]
ensure => latest,
provider => pip,
}
Related videos on Youtube
Tom Purl
Experienced systems engineer specializing in architecting, implementing and maintaining large distributed systems who is looking for a more technically challenging role.
Updated on September 18, 2022Comments
-
Tom Purl over 1 year
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 insudo 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
andgraphite-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?
-
Handyman5 almost 12 yearsThis will cause the
carbon-cache.py
file to be removed each time, but the package will still be installed repeatedly. -
Greg Petersen almost 12 yearsI think you can also use the
onlyif
parameter to do this. -
Mike almost 12 yearsyes you can use only-if