After spending most of they day digging around and researching, I find Puppet's immutable variables are keeping me from properly handling what I'm trying to do, so I want to see if anyone else has some suggestions on how to handle was I need to accomplish.
Goal: Ingest a CSV file provided by a user and generate a start / stop script, dynamically, for every server in scope, based on CSV file. CSV Format: SERVER,start command Example. SERVERA, /usr/local/bin/prog start databasea SERVERA, /usr/local/bin/prog start databaseb SERVER1, /usr/local/bin/prog start database123 The basic design I had in mind for the manifest is to: 1. Read in the file as provided, 2. Convert <A>,<B> to downcase(A) => B 3. if $hostname == A $my_server_script_lines = $my_hash[A][B] file { ... content => template("basic_start_script"), } 4. Create a template that runs through the $my_server_script_lines to put each start line under start) and under stop) after doing a substr replacement of start for stop in B. Code so far include stdlib $my_data = file("/home/me/database.csv") $my_subst = downcase(split($my_data2,'[,\n]')) $my_hash = hash($my_subst) notice ($my_hash[SERVERA]) $ puppet apply --verbose test.pp Info: Loading facts *Notice: Scope(Class[main]): '/usr/local/bin/prog start databaseb'* Notice: Compiled catalog for myhost.net in environment production in 0.16 seconds Info: Applying configuration version '1484340247' Notice: Applied catalog in 0.03 seconds Here are the values of the variables as it processes through $my_data = "SERVERA,/usr/local/bin/prog start databasea SERVERA,/usr/local/bin/prog start databaseb SERVERB,/usr/local/bin/prog start database123" $my_subst = [servera, '/usr/local/bin/prog start databasea' , servera, '/usr/local/bin/prog start databaseb' , serverb, '/usr/local/bin/prog start database123' ] $my_hash = {servera => '/usr/local/bin/prog start databaseb' , serverb => '/usr/local/bin/prog start database123' } So I already know why the hash conversion dropped the "start databasea" for the servera key, what I can't seem to figure out is how to have it convert into a array of value pairs for a specific key. { servera => ['/usr/local/bin/prog start databasea', '/usr/local/bin/prog start databaseb'], serverb => ['/usr/local/bin/prog start database123'] } I tried various iterations of .each to try to create and fill the array pointed to by the hash, but Puppet doesn't permit that as it would be changing an already assigned variable / hash. I was able use the $my_subst variable in an erb template to create the start/stop lines. It worked ok for the 3 line example above, but when I got to dozens of servers / start lines being applied to hundreds of servers on each check-in it soon killed the CPU in my master server as it ran through a loop checking if $hostname == servername. Is it possible to have Puppet handle parsing the data in $my_substr, or even right from the raw file data to do the following? 1. Run through incoming data to fill start command array. ['/usr/local/bin/prog start databasea', '/usr/local/bin/prog start databaseb'] 2. Assign that to the array of key-pairs. { servera => ['/usr/local/bin/prog start databasea', '/usr/local/bin/prog start databaseb'], serverb => ['/usr/local/bin/prog start database123'] } Thanks! -- 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/4fa9b2d3-103c-413f-9be2-1f84a16c115e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.