Puppet class with @host.provision_interface.ip parameter


is it possible to access the IP address and netmask defined for provisioning in a puppet class?


so far i have

$test = $::foreman_interfaces[0]['ip']

Now i need to filter the $::foreman_interfaces array to only show $::foreman_interfaces[0]['primary'] = true.

Does anyone know how to do that in puppet?

Ok. Now i got it:

$test1 = $::foreman_interfaces.map | $hash | { if ($hash['primary']) {$hash['ip']} }
$test = $test1.filter | $ip | {$ip =~ NotUndef}

I hope this helps someone else.

You can usually see everything available from the host page. Click on the “YAML” button to see which parameters are set from foreman. Click on the “Facts” button to see the puppet facts.

The puppet filter function lets you filter through an array. I have this:

  $primary = filter($::foreman_interfaces) |$i| { $i['primary'] == true }
  if length($primary) == 0 {
    fail('No primary interface defined')
  } elsif length($primary) > 1 {
    fail('Multiple primary interfaces defined')
  } elsif ! $primary[0]['managed'] {
    warning("${::fqdn}: primary interface ${primary[0]['identifier']} is not managed")
    notify { "${::fqdn}: primary interface ${primary[0]['identifier']} is not managed": }

$primary is the filtered array. If it goes through the code above, $primary[0] is (only) primary interface.

You could also use a smart class parameter and override the default value in foreman to <%= @host.provision_interface.ip %> or <%= @host.ip %> (which is the ip of the primary interface)

Thank you for helping me out.

Using filter() and validate it seems to be a nice solution.