How to use a each loop on class parameter

asked 2016-10-27 15:48:33 -0600

Neutrall gravatar image

I have a puppet classe with more than 300 parameter (for firewall configuration).

I'm using inisetting to set different module into the firewall. Currently, for every setting, I need to write a inisetting command EX :

   ini_setting { "my_": 
    notify  => Service['myfirewall'], 
    ensure  => present, 
    path    => '/etc/firewall.conf',    
    section => '', setting => 'TCP_IN',
    value   => "\"${tcp_in}\"",
  }

Is there a way I could use a each loop to parse all the class parameter at once EX :

$classparam.each | String $fieldname, String $value | {
  $param = upcase(${fieldname}),
  ini_setting { "my_${fieldname}": 
    notify  => Service['myfirewall'], 
    ensure  => present, 
    path    => '/etc/firewall.conf',    
    section => '', setting => 'TCP_IN',
    value   => "\"${value }\"",
  }
}

This would take a fer hundred line out of my module, and make it a lot more readable!

Thank you for all input!

edit retag flag offensive close merge delete

Comments

I think you would need to pas an array or hash instead of 300 separate parameters to loop over them.

pascal gravatar imagepascal ( 2016-10-31 08:18:26 -0600 )edit

The reason why I'm passing the argument this way is to permit our Tech to modify some setting within the Forman GUI Smart class Parameter. Currently they don't have SSH authorisation into the main Puppet Server.

Neutrall gravatar imageNeutrall ( 2016-10-31 10:25:04 -0600 )edit