Ask Your Question
0

include a parameter conditionally

asked 2017-04-14 12:49:49 -0600

Here's a corosync define I have:

define cs_pacemaker::primitives::ip ($ip, $mask = 24, $monitor_interval = '10s', $stickiness = 0) {
  cs_primitive { $name:

    primitive_class => 'ocf',
    primitive_type  => 'IPaddr2',
    provided_by     => 'heartbeat',

    parameters      => {
      'ip'           => $ip,
      'cidr_netmask' => $mask
    },

    operations      => {
      'monitor' => {
      'interval' => $monitor_interval,
      }
    },

    metadata        => {
      'stickiness' => $stickiness
    },
  }
}

The problem is that I want to include the "metadata" block ONLY if $stickiness is over 0. What's the best way to do this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-04-16 23:26:04 -0600

natemccurdy gravatar image

You can use an if statement to check the value of $stickiness, this this:

define cs_pacemaker::primitives::ip (
  $ip,
  $mask             = 24,
  $monitor_interval = '10s',
  $stickiness       = 0,
) {

  if $stickiness > 0 {
    $metadata = { stickiness => $stickiness }
  } else {
    $metadata = undef
  }

  cs_primitive { $name:
    primitive_class => 'ocf',
    primitive_type  => 'IPaddr2',
    provided_by     => 'heartbeat',
    parameters      => {
      'ip'           => $ip,
      'cidr_netmask' => $mask
    },
    operations      => {
      'monitor'  => {
        'interval' => $monitor_interval,
      }
    },
    metadata        => $metadata,
  }

}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-04-14 12:49:49 -0600

Seen: 54 times

Last updated: Apr 16