Issue setting class parameter based on another class parameter (same class)

15 views
Skip to first unread message

Matthew Kennedy

unread,
Apr 22, 2014, 5:28:11 PM4/22/14
to puppet...@googlegroups.com
I have a class parameterized class that looks similar to...

class blahapp::app (
  $sor_host_ip          = hiera('blahapp::app::sor_host_ip'),
  $rep_host_ip          = hiera('blahapp::app::rep_host_ip',       $sor_host_ip)
) {
  if !($rep_host_ip) {
    fail("Unable to set rep_host_ip. sor_host_ip is set to ${sor_host_ip}. Contact SystemOperations.")
  }
}

The intention is to have $rep_host_ip set to whatever $sor_host_ip is unless we need to set it to something else.

Most of the time this works and everything is happy... randomly, and I haven't been able to reliably replicated the issue, $rep_host_ip ends up being blank, $sor_host_ip is always set correctly. The only 'fix' is to kill everything using ruby, restart apache (passenger) AND hope that no puppet runs happen before the puppet master completes its puppet run.  This can often mean several apache restarts until it starts working again.

The fail() ensures that if we run into this issue we know and can do the restart dance...but this is highly annoying as it breaks randomly.

Has anyone seen something like this/have suggestions to help TS?

Puppet Open: 2.7.25
Hiera and PuppetDB1.6.3
Running under passenger

jcbollinger

unread,
Apr 23, 2014, 12:06:12 PM4/23/14
to puppet...@googlegroups.com


On Tuesday, April 22, 2014 4:28:11 PM UTC-5, Matthew Kennedy wrote:
I have a class parameterized class that looks similar to...

class blahapp::app (
  $sor_host_ip          = hiera('blahapp::app::sor_host_ip'),
  $rep_host_ip          = hiera('blahapp::app::rep_host_ip',       $sor_host_ip)


It is unreliable for class or definition parameter defaults to refer to other elements of the same parameter list.  Do not do it.  Even if it happens to work in one case, it will fail in others, with no good way to predict whether it will work.  Avoid, avoid, avoid!

 
) {
  if !($rep_host_ip) {
    fail("Unable to set rep_host_ip. sor_host_ip is set to ${sor_host_ip}. Contact SystemOperations.")
  }
}

The intention is to have $rep_host_ip set to whatever $sor_host_ip is unless we need to set it to something else.

Most of the time this works and everything is happy... randomly, and I haven't been able to reliably replicated the issue, $rep_host_ip ends up being blank, $sor_host_ip is always set correctly. The only 'fix' is to kill everything using ruby, restart apache (passenger) AND hope that no puppet runs happen before the puppet master completes its puppet run.  This can often mean several apache restarts until it starts working again.

The fail() ensures that if we run into this issue we know and can do the restart dance...but this is highly annoying as it breaks randomly.

Has anyone seen something like this/have suggestions to help TS?


The usual approach to this sort of problem runs along these lines:


class blahapp::app (
  $sor_host_ip          = hiera('blahapp::app::sor_host_ip'),
  $rep_host_ip          = hiera('blahapp::app::rep_host_ip',       'NOTSET')
) {
  $real_rep_host_ip = $rep_host_ip ? {
    'NOTSET' => $sor_host_ip,
    default => $rep_host_ip
  }
  # use $real_rep_host_ip from here on...
}


John

Reply all
Reply to author
Forward
0 new messages