On 13/07/17 19:00, Mariusz Gronczewski wrote:
Hi,

I've been slowly converting old 3.x codebase (which has seen days of 0.24...) to 4.x and there is a lot of following pattern used for hashes:'

     $hash = {
       "some" => "defaults"
     }
     if $thing_one == "is_true" {
         $hash["option1"] = $thing_one,
     }
     if $thing_two == "is_something" {
         $hash["option2"] = "something"
     }
     else {
         $hash["option2"] = "something else"
     }

etc. Now with immutable hashes I'm forced either to do:'

     $hash1 = {
       "some" => "defaults"
     }
     if $thing_one == "is_true" {
         $hash2 = {
             "option1" => $thing_one,
         }
     }
     else { $hash2 = {} }

     if $thing_two == "is_something" {
         $hash3 = {
             "option2" => "something"
         }
     }
     else {
         $hash3 = {
             "option2" => "something else"
     }
     $hash4 = merge($hash1, $hash2, $hash3, $hash3)

or go the hacky route and go to erb and back to use ruby language to do it.

Am I missing something here ? is there a better way to do it? We have a lot of "get a hash, munge it, feed it to either puppet resource or to external config" pattern used in the code and immutability so far doesn't seem like a very useful property



You can do like what John Bollinger showed - or something like this where you merge hash snippets using + operator.

$hash = { "some" => "defaults" }
+ if $thing_one == "is_true" {
    {"option1" => $thing_one}
  }
  else { {} }
+ if $thing_two == "is_something" {
    {"option2" => "something"}
  }
  else {
    {"option2" => "something else"}
  }

- henrik

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
You received this message because you are subscribed to the Google Groups "Puppet 
Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/ol7f3r%24vg5%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to