Ask Your Question

How can I handle config files with multiple, same named directives?

asked 2013-03-13 17:06:00 -0600

llowder gravatar image

I'm trying to write a module (icinga in this instances though that doesn't matter so much in this case) and while trying to template the main config file I noticed that a couple of the directives were repeated. Normally I just roll through the config file, and everywhere I see a directive, I just replace it with a variable that has the same name (or as close to the same as puppet allows). For example, cfg_dir=<%= @cfg_dir %>

# Commands definitions

# Debian also defaults to using the check commands defined by the debian
# nagios-plugins package ...
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-03-13 17:19:36 -0600

ramindk gravatar image

updated 2013-03-13 17:22:09 -0600

Steal a page from the puppetlabs-haproxy module. For any value with an array as the value it loops the key and value for each value.


  class { 'haproxy':
    enable           => true,
    global_options   => {
      'log'     => "${::ipaddress} local0",
      'chroot'  => '/var/lib/haproxy',
      'pidfile' => '/var/run/',
      'maxconn' => '4000',
      'user'    => 'haproxy',
      'group'   => 'haproxy',
      'daemon'  => '',
      'stats'   => 'socket /var/lib/haproxy/stats'
    defaults_options => {
      'log'     => 'global',
      'stats'   => 'enable',
      'option'  => 'redispatch',
      'retries' => '3',
      'timeout' => [
        'http-request 10s',
        'queue 1m',
        'connect 10s',
        'client 1m',
        'server 1m',
        'check 10s'
      'maxconn' => '8000'


<% global_options.sort ...
edit flag offensive delete link more


that's pretty much what I thought I was going to have to do, but was hoping for a cleaner way.

llowder gravatar imagellowder ( 2013-03-13 17:35:58 -0600 )edit

You other option is not to manage the settings at all. /etc/icinga/{commands.d,objects.d,hosts.d,hostgroups.d} and set them all as confdirs and drop any ...(more)

ramindk gravatar imageramindk ( 2013-03-13 17:56:44 -0600 )edit

Your Answer

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

Add Answer

Question Tools


Asked: 2013-03-13 17:06:00 -0600

Seen: 550 times

Last updated: Jun 21 '13