I'm trying to push parameters from foreman to my puppet class to generate configuration file.
Eeach file should be like this:
file1
DB_USERNAME=toto
DUMP_TYPE=full
[...]
file2
DB_USERNAME=toto
DUMP_TYPE=full
[...]
I define a parameter in Foreman which is an array of hashes
bacula_client dumpCfg [{"techno"=>"oracle", "DB_USERNAME"=>"toto", "DUMP_TYPE"=>"full", ...},
{"techno"=>"mysql", "DB_USERNAME"=>"toto", "DUMP_TYPE"=>"full", ...}]
I would like to know if it is possible to do something like that to generate for instance 2 different config files as I get a 'Ressource title must be a string' when calling dumpdb
class bacula_client (
$isDirector = false,
$backupCrons = [],
$isHostConcentrator = false,
$dumpCfg = [],
define bacula_client::dumpdb () {
$techno = $name['techno']
$dbusername = $name['DB_USERNAME']
$dumptype = $name['DUMP_TYPE']
# call a function that generates the files
}
[.....]
}#myclass
bacula_client::dumpdb{$dumpCfg:}
Thank you in advance,
Error message says it all. You're naming a resource using a hash. Supposed to be string.
Try it this way:
define bacula_client::dumpdb ($dumpCfg) {
$techno = $dumpCfg['techno']
$dbusername = $dumpCfg['DB_USERNAME']
$dumptype = $dumpCfg['DUMP_TYPE']
# call a function that generates the files
}
bacula_client::dumpdb{'file1': dumpCfg => $dumpCfg[0] }
bacula_client::dumpdb{'file2': dumpCfg => $dumpCfg[1] }
Notice the 'file1' and 'file2'. Those are the resource names that need to be strings and must be unique. Data is passed in as a parameter.
Not sure if youre array/hash usage works or not. Didn't test and I don't pass data around that way very often.
And do yourself a favor and put your define in it's own file, not in the middle of a class. Will save you headaches later (like the one I have trying to make sense of 400+ line classes with all sorts of fun in them accumulated over the last 2 years).
Edit: grammar