No description
Find a file
Justin Stoller 25e7c2845e Remove basic spec
This removes the "basic_spec" as it is largely a sanity check against
the env/tooling.  The spec itself is problematic because in Puppet
Enterprise a module will be in 'sitemoduledir' or 'distmoduledir'
depending on whether it's included in PE as part of the distribution or
not.  However it will always be in 'distmoduledir' for FOSS.
2014-02-13 15:38:21 -08:00
lib/puppet Fix the regex t fix a bad match 2013-12-05 11:47:28 -08:00
spec Remove basic spec 2014-02-13 15:38:21 -08:00
tests Style fixes 2013-04-10 14:57:39 +02:00
.fixtures.yml (FM-161) Add beaker tests for parameter coverage 2014-01-27 10:33:45 -08:00
.gitignore actually write a file in spec/fixtures/tmp 2013-07-16 10:18:15 +01:00
.travis.yml Merge pull request #68 from ghoneycutt/test_puppet_v3_4 2014-01-23 14:24:34 -08:00
CHANGELOG Release 1.0.1 2014-02-12 11:06:57 -08:00
Gemfile Allow custom gemsource 2014-02-11 16:34:43 -08:00
LICENSE Added license file w/Apache 2.0 license 2012-11-06 13:53:15 -08:00
metadata.json Add empty dependencies section. 2013-10-08 15:13:13 -07:00
Modulefile Release 1.0.1 2014-02-12 11:06:57 -08:00
Rakefile Tweak the Gemfile to be better for development, add a Rakefile. 2013-07-15 16:22:30 -04:00
README.markdown Fix link to travis in README 2014-01-23 17:43:26 -05:00

Build Status

INI-file module

This module provides resource types for use in managing INI-style configuration files. The main resource type is ini_setting, which is used to manage an individual setting in an INI file. Here's an example usage:

ini_setting { "sample setting":
  ensure  => present,
  path    => '/tmp/foo.ini',
  section => 'foo',
  setting => 'foosetting',
  value   => 'FOO!',
}

A supplementary resource type is ini_subsetting, which is used to manage settings that consist of several arguments such as

JAVA_ARGS="-Xmx192m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof "

ini_subsetting {'sample subsetting':
  ensure  => present,
  section => '',
  key_val_separator => '=',
  path => '/etc/default/pe-puppetdb',
  setting => 'JAVA_ARGS',
  subsetting => '-Xmx',
  value   => '512m',
}

implementing child providers:

The ini_setting class can be overridden by child providers in order to implement the management of ini settings for a specific configuration file.

In order to implement this, you will need to specify your own Type (as shown below). This type needs to implement a namevar (name), and a property called value:

example:

#my_module/lib/puppet/type/glance_api_config.rb
Puppet::Type.newtype(:glance_api_config) do
  ensurable
  newparam(:name, :namevar => true) do
    desc 'Section/setting name to manage from glance-api.conf'
    # namevar should be of the form section/setting
    newvalues(/\S+\/\S+/)
  end
  newproperty(:value) do
    desc 'The value of the setting to be defined.'
    munge do |v|
      v.to_s.strip
    end
  end
end

This type also must have a provider that utilizes the ini_setting provider as its parent:

example:

# my_module/lib/puppet/provider/glance_api_config/ini_setting.rb
Puppet::Type.type(:glance_api_config).provide(
  :ini_setting,
  # set ini_setting as the parent provider
  :parent => Puppet::Type.type(:ini_setting).provider(:ruby)
) do
  # implement section as the first part of the namevar
  def section
    resource[:name].split('/', 2).first
  end
  def setting
    # implement setting as the second part of the namevar
    resource[:name].split('/', 2).last
  end
  # hard code the file path (this allows purging)
  def self.file_path
    '/etc/glance/glance-api.conf'
  end
end

Now, the individual settings of the /etc/glance/glance-api.conf file can be managed as individual resources:

glance_api_config { 'HEADER/important_config':
  value => 'secret_value',
}

Provided that self.file_path has been implemented, you can purge with the following puppet syntax:

resources { 'glance_api_config'
  purge => true,
}

If the above code is added, then the resulting configured file will only contain lines implemented as Puppet resources

A few noteworthy features:

  • The module tries hard not to manipulate your file any more than it needs to. In most cases, it should leave the original whitespace, comments, ordering, etc. perfectly intact.
  • Supports comments starting with either '#' or ';'.
  • Will add missing sections if they don't exist.
  • Supports a "global" section (settings that go at the beginning of the file, before any named sections) by specifying a section name of "".