Ask Your Question
0

Duplicate declaration: cannot redeclare resouces

asked 2015-11-04 23:28:51 -0500

Pandey Manish gravatar image

Hi,

I wants to create a class file that will do below steps

  1. Purge directory "pki"
  2. copy certificate ca.pem and $::hostname.localdomain.pem from location "certs" to same directory "pki"
  3. rename the .pem certificates to .crt present in the same directory "pki" .
  4. copy key file $::hostname.localdomain.pem from location "private_keys" to same "pki"
  5. rename the .pem key file to .crt present in directory "pki" .

But when i am executing the below code i am getting error ===>

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: File[C:/Program Files (x86)/ICINGA2/etc/icinga2/pki] is already declared in file /etc/puppet/environments/production/modules/winnms/manifests/config.pp:15; cannot redeclare at /etc/puppet/environments/production/modules/w innms/manifests/config.pp:27 on node r8systsnode03.localdomain Warning: Not using cache on failed catalog Error: Could not retrieve catalog; skipping run

<===

MY CONFIG CLASS CODE IS

class win_nms::config {

    include win_nms::params

if $osfamily == 'windows' {

    file { "purge_dir":
            name    => "$::win_nms::params::nms_pki_pub_dir",
            ensure  => directory,
            recurse => true,
            purge   => true,
    }


    file { 'pki_cert':
            path                    => "$::win_nms::params::nms_pki_pub_dir",
            ensure                  => directory,
            source_permissions      => ignore,
            recurse                 => true,
            source                  => "C:/ProgramData/PuppetLabs/puppet/etc/ssl/certs",
    }

    exec { "Rename_crt":
            command => "cmd.exe /c ren *.pem *.crt",
            path    => "C:/Windows/System32",
            cwd     => "$::win_nms::params::nms_pki_pub_dir",
    }

    file { "pki_key":
            name                    => "$::win_nms::params::nms_pki_pri_dir",
            ensure                  => 'directory',
            source_permissions      => ignore,
            source                  => "C:/ProgramData/PuppetLabs/puppet/etc/ssl/private_keys",
    }

MY PARAMS CLASS CODE IS

class win_nms::params {

case $::osfamily {

windows: {
    $nms_package_name = 'Icinga2-v2.3.10'
    $nms_pki_pub_dir          = 'C:/Program Files (x86)/ICINGA2/etc/icinga2/pki/'
    $nms_pki_pri_dir          = 'C:/Program Files (x86)/ICINGA2/etc/icinga2/pki/'
    $nms_service_name = 'icinga2'
}
default: {
    fail("Module icinga does not support osfamily: ${::osfamily}")
}

}

}

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-11-13 08:52:45 -0500

DarylW gravatar image

I believe your problem is that you have two separate resources with

name                    => "$::win_nms::params::nms_pki_pri_dir",

What you are effectively asking puppet to do is to apply two differently configured resources to the same file.

Remember that puppet is declarative - you want to define the end state of your system, not a series of steps to transform your system. If you absolutely have to do several operations to the same directory in order, be sure to use either ordering arrows or require/before parameters to ensure resource order.

More complicated, order specific operations can either be constructed from a sequence of exec statements, or you could create a script which would get run only under the instances where it needs run.

I'm not familiar with using puppet on windows, but I can try to help you out with more examples if you still need assistance.

edit flag offensive delete link more

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-11-04 23:28:51 -0500

Seen: 1,038 times

Last updated: Nov 13 '15