Search code examples
puppet

Duplicate declaration error with puppet


I try to create a folder then trying to copy some files into it like below.

init.pp

$tempfolder = "D:/TempFolder/" 


file { [ $tempfolder ]:
    ensure => "directory",
}

file { [ $tempfolder ]:

    ensure => present,
    recurse => true,
    source => "E:/TestFiules",
}

When I try to run this, it is giving below error

Error: Duplicate declaration: File [ D:/TempFolder/ ] is already declared.

What is the wrong in the usage?


Solution

  • For reference: http://docs.puppetlabs.com/guides/techniques.html#how-can-i-manage-whole-directories-of-files-without-explicitly-listing-the-files

    Thus you could do

    file { "$tempfolder":
        ensure => directory,
        recurse => true,
        source => "E:/TestFiules",
    }
    

    The ensure => directory also ensures that it will be present, so you don't have to declare it again.