Passing Parameter as Array to Puppet Modules

I've seen previous discussions on the inability to pass an array or
hash as a parameter, and am exploring ways to work around this. I
have very little Ruby programming experience, and am hoping someone
here may have done something similar.

Here's a hash I currently have defined for a node…

backuppc_db_dumps =  {
    'example' => {
            'backup_dir'    => '/var/www/example.com',
            'databases' => 'example',
            'dump_dir'  => '/backups/example-sqldumps',
    },
    'general' => {
            'backup_dir'    => '/etc',
            'databases'     => 'mysql',
            'dump_dir'  => '/backups/misc-sqldumps',
    },
}

the string looks like so…

backuppc_db_dumps = "{'general'=>{'dump_dir'=>'/backups/misc-
sqldumps', 'databases'=>'mysql', 'backup_dir'=>'/etc'},
'anth'=>{'dump_dir'=>'/backups/example-sqldumps', 'datab
ases'=>'example', 'backup_dir'=>'/var/www/example.com'}}"

I have successfully tested using a custom Puppet function to convert
the string back into a hash. The problem is that the only way I've
been able to turn that back into a hash is using "eval", which I'd
prefer not to use.

I've tried converting that string to YAML and then to hash with no
luck. I can't find a way to represent the information in a single
string that can be manipulated with YAML.load() or any of the other
various methods that have been suggested around the net.

Are there any changes post Foreman-0.3 that are going to change the
way parameters can be defined for nodes? I'd be happy to help work in
a change to Foreman if it's not already been done in a development
version.

Thanks

  • Trey

> I've seen previous discussions on the inability to pass an array or
> hash as a parameter, and am exploring ways to work around this. I
> have very little Ruby programming experience, and am hoping someone
> here may have done something similar.
>
> Here's a hash I currently have defined for a node…
>
> backuppc_db_dumps = {
> 'example' => {
> 'backup_dir' => '/var/www/example.com',
> 'databases' => 'example',
> 'dump_dir' => '/backups/example-sqldumps',
> },
> 'general' => {
> 'backup_dir' => '/etc',
> 'databases' => 'mysql',
> 'dump_dir' => '/backups/misc-sqldumps',
> },
> }
>
> the string looks like so…
>
> backuppc_db_dumps = "{'general'=>{'dump_dir'=>'/backups/misc-
> sqldumps', 'databases'=>'mysql', 'backup_dir'=>'/etc'},
> 'anth'=>{'dump_dir'=>'/backups/example-sqldumps', 'datab
> ases'=>'example', 'backup_dir'=>'/var/www/example.com'}}"
>
> I have successfully tested using a custom Puppet function to convert
> the string back into a hash. The problem is that the only way I've
> been able to turn that back into a hash is using "eval", which I'd
> prefer not to use.

You can choose json or yaml.

> I've tried converting that string to YAML and then to hash with no
> luck. I can't find a way to represent the information in a single
> string that can be manipulated with YAML.load() or any of the other
> various methods that have been suggested around the net.

In Puppet Enterprise 1.2, the functions in stdlib can serve as stop
gap until Dashboard/Foreman fully support array/hash. Specifically
parseyaml and parsejson:


Thanks,

Nan

··· On Sun, Aug 21, 2011 at 8:22 PM, treydock wrote:

The parseyaml function was exactly what I was trying to achieve, but
my problem is how to represent my current hashes in the correct format
to be used with YAML.load.

Could you possibly give me an example of what a string accepted by
YAML.load would look like?

Thanks

  • Trey
··· On Aug 22, 12:10 am, Nan Liu wrote: > On Sun, Aug 21, 2011 at 8:22 PM, treydock wrote: > > I've seen previous discussions on the inability to pass an array or > > hash as a parameter, and am exploring ways to work around this. I > > have very little Ruby programming experience, and am hoping someone > > here may have done something similar. > > > Here's a hash I currently have defined for a node... > > > backuppc_db_dumps = { > > 'example' => { > > 'backup_dir' => '/var/www/example.com', > > 'databases' => 'example', > > 'dump_dir' => '/backups/example-sqldumps', > > }, > > 'general' => { > > 'backup_dir' => '/etc', > > 'databases' => 'mysql', > > 'dump_dir' => '/backups/misc-sqldumps', > > }, > > } > > > the string looks like so... > > > backuppc_db_dumps = "{'general'=>{'dump_dir'=>'/backups/misc- > > sqldumps', 'databases'=>'mysql', 'backup_dir'=>'/etc'}, > > 'anth'=>{'dump_dir'=>'/backups/example-sqldumps', 'datab > > ases'=>'example', 'backup_dir'=>'/var/www/example.com'}}" > > > I have successfully tested using a custom Puppet function to convert > > the string back into a hash. The problem is that the only way I've > > been able to turn that back into a hash is using "eval", which I'd > > prefer not to use. > > You can choose json or yaml. > > > I've tried converting that string to YAML and then to hash with no > > luck. I can't find a way to represent the information in a single > > string that can be manipulated with YAML.load() or any of the other > > various methods that have been suggested around the net. > > In Puppet Enterprise 1.2, the functions in stdlib can serve as stop > gap until Dashboard/Foreman fully support array/hash. Specifically > parseyaml and parsejson: > > https://github.com/puppetlabs/puppetlabs-stdlib/blob/master/lib/puppe...https://github.com/puppetlabs/puppetlabs-stdlib/blob/master/lib/puppe... > > Thanks, > > Nan