Writing quotes in values with puppetlabs-inifile

asked 2016-02-16 13:15:19 -0600

al4 gravatar image

I've been using puppetlabs-inifile to manage configuration files for various services, and I also want to use it to manage InfluxDB. InfluxDB is written in Go and is strict about the configuration file format - i.e. strings must be quoted, while ints and booleans must not.

The problem; puppetlabs-inifile strips out the quotes, but I can't find any code to indicate that this is deliberate. It seems, to my untrained eye, to be incidental. For example, the following ini_setting declaration:

ini_setting { "foo_bar":
  section = 'foo',
  setting = 'bar',
  value   = '"boz"'

Results in:

bar = boz

Same applies when value => "'boz'", and even value => '\"boz\"'

I figured it was probably due to the way puppet handles strings, so I created a custom provider in my module, which extends ini_setting to append the quotes explicity:

  # set ini_setting as the parent provider
  :parent => Puppet::Type.type(:ini_setting).provider(:ruby)
) do

  def value
    # Add encapsulating quotes for strings
    if resource[:quote_value]
        rv = resource[:value].prepend('"') << '"'
        puts rv
        return rv

  def quoted_value

The type, influxdbsetting, is a direct copy-paste of inisetting.rb, with the addition of:

newparam(:quote_value, :boolean => true, :parent => Puppet::Parameter::Boolean) do
  desc 'Quote the value'
  defaultto :false

Using this type, the puts statement returns the strings as expected, so I believe the stripping is happening on the output side.

An obvious solution, would be to use ini_subsetting, but there's a snag there too.

InfluxDB's modules use two square brackets for the section heading, so I also need the section_prefix and section_suffix parameters, which are provided by inisetting but not inisubsetting.

My question is, where puppetlabs-inifile are the quotes being stripped? Having read through the code I can't see where it's happening and thus what I need to override.

Any advice appreciated!

edit retag flag offensive close merge delete