lundi 10 août 2015

Puppet advanced default params

Basically I have a puppet class cassandra_manager::params. I have a ton of params set like so:

# etc...
$cluster_name = undef,
$num_tokens = 256,
$initial_token = undef,
$hinted_handoff_enabled = true,
# etc...

Now most of these ones set undef, I just handle in my template just commenting it out if it's undef.

But there are a few that I need to use some previous params, and facts to figure out the defaults. Here is one main example:

$memtable_flush_writers = undef,

I then try to set it later like this:

$min_from_cores_and_disks = min([ $::processorcount, size(split($::hard_drives, ',')) ])
if !$memtable_flush_writers {
  if 0 + (0 + $min_from_cores_and_disks[0]) > 8 or (0 + $min_from_cores_and_disks[0]) < 2 {
    if (0 + $min_from_cores_and_disks[0]) < 2 {
      $memtable_flush_writers = 2
    }
    elsif (0 + $min_from_cores_and_disks[0]) > 8 {
      $memtable_flush_writers = 8
    }
  } else {
    $memtable_flush_writers = (0 + $min_from_cores_and_disks[0])
  }
}

Then puppet tells me I can't set $memtable_flush_writers because all variables are immutable in puppet.

So then I changed checking for whether the variable was "false" and didn't set the variable up above, but that just told me the obvious, that $memtable_flush_writers wasn't set.

What's the best way that I can still get the functionality from the if statements above without having these errors pop up. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire