Ask Your Question
0

How do I check if multiple packages are installed before installing them

asked 2015-10-18 18:03:21 -0500

sinaowolabi gravatar image

I have a list of packages that should be installed on (mostly) rpm based systems. I am installing them like so:

    Package { ensure => "installed" }
    $enhancers = [ "graphviz", "gcc-c++", "goaccess", "awstats", "screen", "strace", "nmap", "wget", "curl", "tcpdump", "vim-enhanced", "bind-utils", "tcptraceroute", "traceroute", "policycoreutils-python", "nc", "sharutils", "mutt", "ngrep", "nload", "htop" ]
    package { $enhancers: }
    }

Please what is the best way to insure that these packages are not installed first? I have tried using

    unless => $enhancers

but this does throw up errors. Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-10-18 23:59:20 -0500

GregLarkin gravatar image

There's no need to do that because Puppet is idempotent. That is, you simple define the desired end state of the system, and Puppet will enforce it. If 3 of the packages are not yet installed, Puppet will only install those three. If all of the packages are not yet installed, Puppet will install all of them. This happens without any additional code.

Puppet will then continue to ensure that the packages are installed on the system. If one package is removed, Puppet will reinstall it for you on its next run.

Please have a look at the documentation for idempotency for more information.

edit flag offensive delete link more

Comments

Ah! Thank you, this makes sense. The problem I am facing is, prior to this command, I have another command written to purge a package, which runs every time and is making the repos to block me. package { "nmap-ncat": ensure => "purged" } Shouldn't this be idempotent as well?

sinaowolabi gravatar imagesinaowolabi ( 2015-10-19 02:40:07 -0500 )edit

That resource should be idempotent as well. As you saying that the resource is applied even when the package has already been removed from the system? If so, can you change "purged" to "absent" and see if that fixes it?

GregLarkin gravatar imageGregLarkin ( 2015-10-19 14:30:38 -0500 )edit

Hi Greg, sorry for the late reply, but your suggestion seems to have worked. Thanks!

sinaowolabi gravatar imagesinaowolabi ( 2015-10-21 05:34:21 -0500 )edit

Awesome, glad to hear it!

GregLarkin gravatar imageGregLarkin ( 2015-10-26 19:44:34 -0500 )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

Stats

Asked: 2015-10-18 18:03:21 -0500

Seen: 468 times

Last updated: Oct 18 '15