How to loop "exec" in a manifest

380 views
Skip to first unread message

Malintha Adikari

unread,
Jun 25, 2014, 8:34:47 AM6/25/14
to puppet...@googlegroups.com
Hi,

My requirement is copy some files from agent source to agent's destination. I have the list of files. I store the list of file as a hash looks follows

$foo = [{"addr" => $source1, "dest" => $destination1},                                    
          {"addr" =>  $source2, "dest" => $destination2}]


And then I define a type as follows to go through the hash and execute copy command

 define bar () {                                                     
    $var1 = $name["addr"]                                                      
    $var2 = $name["dest"]
 
exec { "myexec":
    command => "cp  ${var1} ${var2}",
    cwd => $agentLocation,
    mode => "0777",
    path      => $command_path,
    logoutput => true,
    timeout => 3600,   
}
                                             
                                              
  }



But this gives me exception says

 Error 400 on SERVER: Duplicate declaration: Exec[myexec] is already declared in file /etc/puppet/modules/config/manifests/init.pp:78; cannot redeclare at /etc/puppet/modules/config/manifests/init.pp:78


How can I correct this or is there any alternative for this specific task ?

Regards,
Malintha Adikari

Spencer Krum

unread,
Jun 25, 2014, 11:06:47 AM6/25/14
to puppet...@googlegroups.com

First, you can use the file type instead of the exec type. Source can be a local path.
Second, in a define you must add $name to the title of every resource to prevent duplicate definition errors.
Third, I would build a hash of every file in your list, then call create_resources() on that hash.
Fourth, using a define like you are doing is the right idea, but set the names of the files to be managed as parameters to the type.
Fifth, the file type can recurse through subdirectories, this might help you.

Cheers,
Spencer

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/1fe78ed2-d4c1-4c36-aa8d-c3c6dee26a14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages