0
votes

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?

3

3 Answers

1
votes

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.

0
votes

A node can only have one resources with the same name declared, in this case the $tempfolder. Either the $tempfolder is created empty (your first declaration) or created and populated with your E:/TestFiule content (the second declaration).

Note that you can drop the array syntax it's often used to create multiple directory at once or ensure an order like creating a tree

0
votes

I came across this message when, but the error was:

Error: Duplicate declaration: File[] is already declared in file init.pp:40; cannot redeclare at init.pp:46 on node (redacted)

The file it was looking up was not defined, because my Hiera configuration was incorrect. As a result it was declaring two files named "".

Verify that Hiera is passing values correctly.