Set up hiera correctly, add a yaml file to your hierarchy, and and 
translate the CSV file to YAML:

I'm a perl geek, so:
#!/bin/perl

while(<>)  {
  chomp; 
  tr/A-Z/a-z/;
  my @a = split(/\,/);
  push(@{$hash{$a[0]}}, $a[1]);
}
for my $srv (sort(keys(%hash)))  {
  print "startup::$srv\n";
  for my $cmd (@{$hash{$srv}})  {
    print "  - $cmd\n";
  }
}


... yes, that array syntax in the hash is hideous.  ;)

Also, I know I should be using CSV and YAML modules, but the example was 
simple enough.

That should produce something like:

startup::servera:
  - /usr/local/bin/prog start databasea
  - /usr/local/bin/prog start databaseb 
startup::serverb:
  - /usr/local/bin/prog start database123

Although I'd probably drop the "/usr/local/bin/prog start", since it seems 
to be common to all.

Then a class:

class startup  {

  $array = hiera(startup::$hostname, "none")

  if (! $array == "none") {
   < do stuff >
 }
}



I'm assuming serverb doesn't need to know servera's business (loading the 
entire thing on every server seems wasteful to me), but if it does, change 
the yaml to:

startup:
  servera:
    - command 1
    - command 2
  serverb:
    - command 1

And then just load the entire hash:

$hash = hiera("startup")

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/496ef25d-311f-4a9c-8a4f-52abf292d6e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to