Ask Your Question
1

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

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

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
cfg_file=/etc/icinga/commands.cfg

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

1 Answer

Sort by ยป oldest newest most voted
1

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

ramindk gravatar image

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

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.

https://github.com/puppetlabs/puppetlabs-haproxy/blob/master/manifests/init.pp

some/node.pp

  class { 'haproxy':
    enable           => true,
    global_options   => {
      'log'     => "${::ipaddress} local0",
      'chroot'  => '/var/lib/haproxy',
      'pidfile' => '/var/run/haproxy.pid',
      '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'
    },
  }

haproxy/templates/haproxy-base.cfg.erb

global
<% global_options.sort ...
(more)
edit flag offensive delete link more

Comments

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 -0500 )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 -0500 )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

Stats

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

Seen: 523 times

Last updated: Jun 21 '13