This is *the* classic case for a defined type.
define my_templated_file() {
$directory = "/home/malintha/adikari5"
file { "$directory/$name/":
ensure => present,
owner => 'root',
group => 'root',
mode => '0777',
content => template("config/${name}.erb"),
}
Then just
my_templated_file { $filenames: }
Note that I fixed the duplicate ".xml" in the template name for you.
HTH,
Felix