1

I would like to test if multiple packages exist in my environment or not, based on this test I would like to generate the final catalog.

if !defined( Package[ 'apache2' ] ) {
    package { 'apache2':
        ensure  => installed,
    }
}
if !defined( Package[ 'libapache2-svn' ] ) {
    package { 'libapache2-svn':
        ensure  => installed,
    }
}

In future I would like to control in the following way:

Package { ensure => "installed" }
$packageList = [ 'apache2', 'libapache2-svn' ]

if !defined( Package[ $packageList ] ) {
    package { $packageList: }
}
Felix Frank
  • 8,125
  • 1
  • 23
  • 30
Anup Singh
  • 313
  • 1
  • 5
  • 18
  • What is your question? – ptierno Sep 26 '15 at 23:12
  • 1
    also.. note that `defined()` does not check to see if a package is installed on your system or not. It checks to see if a `package` resource for that particular package is in the puppet catalog. Even if ensure is set to `absent`, it should still return true. – ptierno Sep 26 '15 at 23:14
  • I understand the concept of catalog. But I am getting error when I pass array of elements in the defined resource. My objective is to loop multiple elements through the defined resource. – Anup Singh Sep 27 '15 at 00:11
  • you mean the `defined` `function` not `resource`. and the function doesnt appear to accept an array argument. https://github.com/puppetlabs/puppet/blob/master/lib/puppet/functions/defined.rb – ptierno Sep 27 '15 at 01:24
  • 1
    This is generally a Bad Idea. See https://github.com/ffrank/puppet-constraints#defined for the reasoning and an alternative approach. – Felix Frank Sep 29 '15 at 14:09

0 Answers0