1
votes

I get the following error from one of my puppet modules:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: Concat[/etc/auto.master] is already declared in file /etc/puppetlabs/puppet/environments/development/modules/autofs/manifests/mount.pp:16; cannot redeclare at /etc/puppetlabs/puppet/environments/development/modules/autofs/manifests/mount.pp:16 on node nbsrvadm-02v.diasemi.com

I am quite new to puppet and no idea what I have done wrong, below are the module files:

Init.pp

class autofs ($master=$autofs::params::master) inherits autofs::params {
  concat { "$master":
    owner  => 'root',
    group  => 'root',
    mode   => '0644',
    notify => Service[$autofs::params::service],
  }
  anchor { 'autofs::begin': }
  class { 'autofs::install': } ->
  class { 'autofs::config': } ~>
  class { 'autofs::service': }
  anchor { 'autofs::end': }
}

The mount.pp class is called by the config class:

 class autofs::config {
  $map_options = hiera('mapOptions')
  create_resources( 'autofs::mount', $map_options)
}

Then then mount.pp looks like the below:

define autofs::mount (
  $mount,
  $mapfile,
  $options,
  $order,
) {
  include autofs::params

  concat::fragment { 'autofs::fragment preamble $autofs::params::master':
    ensure  => present,
    target  => "$autofs::params::master",
    content => "${mount} ${mapfile}.$::site_shortname ${options} \n",
    order   => $order,
  }

  file { $mount:
    ensure => directory,
  }

  file { "${mapfile}.$::site_shortname":
    ensure  => link,
    target => "/usr/share/centrifydc/etc/adauto.pl",
    notify  => Service[$autofs::params::service],
  }

}

And the params class:

==> params.pp <==

class autofs::params {

  case $::operatingsystem {
     RedHat: {
       case $::operatingsystemmajrelease {
         5: {
              $package_version="5.0.1-0.rc2.184.el5"
           }
         6: {
              $package_version="5.0.5-109.el6_6.1"
           }
         default: {
              fail("Module ${module_name} is not supported on ${::operatingsystem} version ${::operatingsystemmajrelease}")
           }
         }
           $master="/etc/auto.master"
           $service="autofs"
           $package="autofs"
           $hasrestart="true"
           $hasstatus="true"
      }
     default: {
       fail("Module ${module_name} is not supported on ${::operatingsystem}")
      }
   }
}

Finally the data in hiera:

---
classes:
  - autofs
mapOptions:
  archived:
    mount: '/archived'
    mapfile: '/etc/auto.archived'
    options: 'ro,defaults,_netdev,tcp'
    order: 01
  cad:
    mount: '/cad'
    mapfile: '/etc/auto.cad'
    options: 'defaults,_netdev,tcp'
    order: 02

When just one entry is configured in hiera the module works as expected. Any help would be really appreciated.

2

2 Answers

1
votes

I think the problem is with this line:

concat::fragment { 'autofs::fragment preamble $autofs::params::master':

Change it to:

concat::fragment { "autofs::fragment preamble ${autofs::params::master}":

You used single quotes, so variables will not be evaluated. More about quoting in puppet here.

UPDATE:

Another problem - you never changed the value of $autofs::params::master. That's why, each time you create an instance of autofs::mount object, it will contain an instance of

Concat::Fragment ["autofs::fragment preamble /etc/auto.master"] 

Change autofs::params::master to variable that actually differs for each autofs::mount, eg:

concat::fragment { "autofs::fragment preamble ${mount}":
0
votes

Your module should get a class autofs if it does not already have it. Move the concat resource there.

class autofs($master=$autofs::params::master) inherits autofs::params {
  concat { "$master":
    owner  => 'root',
    group  => 'root',
    mode   => '0644',
    notify => Service[$autofs::params::service],
  }
}

You can just include this class from your defined type.

Always put singleton resources (things that must not be declared multiple times per node) in classes.