Skip to content

Commit

Permalink
Merge pull request redhat-openstack#128 from mhaskel/1.1.4-prep
Browse files Browse the repository at this point in the history
1.1.4 prep
  • Loading branch information
hunner committed Sep 30, 2014
2 parents 41e2ddb + 3d3a2cf commit db28fa2
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 100 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
##2014-09-30 - Supported Releases 1.1.4
###Summary

This release includes documentation and test updates.

##2014-07-15 - Supported Release 1.1.3
###Summary

Expand Down
299 changes: 206 additions & 93 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,107 +1,220 @@
[![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-inifile.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-inifile)

# 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
#INI file

####Table of Contents

1. [Overview](#overview)
2. [Module Description - What the module does and why it is useful](#module-description)
3. [Setup - The basics of getting started with inifile module](#setup)
* [Setup requirements](#setup-requirements)
* [Beginning with inifile](#beginning-with-inifile)
4. [Usage - Configuration options and additional functionality](#usage)
5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
5. [Limitations - OS compatibility, etc.](#limitations)
6. [Development - Guide for contributing to the module](#development)

##Overview

This module adds resource types to manage settings in INI-style configuration files.

##Module Description

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
The inifile module adds two resource types so that you can use Puppet to manage settings and subsettings in INI-style configuration files.

This 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. intact.

###Noteworthy module features include:

* Supports comments starting with either '#' or ';'.
* Supports either whitespace or no whitespace around '='.
* Adds any missing sections to the INI file.

##Setup

##Beginning with inifile

To manage an INI file, add the resource type `ini_setting` or `ini_subsetting` to a class.

##Usage

Manage individual settings in INI files by adding the `ini_setting` resource type to a class. For example:

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

To control multiple values in a setting, use `ini_subsetting`. For example:

```
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:

You can set up custom child providers that inherit the `ini_setting` provider. This allows you to implement custom resources to manage INI settings for specific configuration files without copying all the code or writing your own code from scratch. This also allows resource purging to be used.

To implement child providers, you'll need to specify your own type. This type needs to implement a namevar (name) and a property called value:

For 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 must also have a provider that uses the `ini_setting` provider as its parent. For example:

Now, the individual settings of the /etc/glance/glance-api.conf file can be managed as individual resources:
```
# 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
```

glance_api_config { 'HEADER/important_config':
value => 'secret_value',
}
Now the individual settings of the /etc/glance/glance-api.conf file can be managed as individual resources:

Provided that self.file_path has been implemented, you can purge with the following puppet syntax:
```
glance_api_config { 'HEADER/important_config':
value => 'secret_value',
}
```

resources { 'glance_api_config'
purge => true,
}
If the self.file_path has been implemented, you can purge with the following Puppet syntax:

If the above code is added, then the resulting configured file will only contain lines implemented as Puppet resources
```
resources { 'glance_api_config'
purge => true,
}
```

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

##Reference

###Type: ini_setting

#### Parameters

* `ensure`: Ensures that the resource is present. Valid values are 'present', 'absent'.

* `key_val_separator`: The separator string to use between each setting name and value. Defaults to ' = ', but you could use this to override the default (e.g., whether or not the separator should include whitespace).

* `name`: An arbitrary name used as the identity of the resource.

* `path`: The INI file in which Puppet will ensure the specified setting.

* `provider`: The specific backend to use for this `ini_setting` resource. You will seldom need to specify this --- Puppet will usually discover the appropriate provider for your platform. The only available provider for `ini_setting` is ruby.

* `section`: The name of the INI file section in which the setting should be defined. Add a global section --- settings that appear at the beginning of the file, before any named sections --- by specifying a section name of "".

* `setting`: The name of the INI file setting to be defined.

* `value`: The value of the INI file setting to be defined.

###Type: ini_subsetting

#### Parameters

* `ensure`: Ensures that the resource is present. Valid values are 'present', 'absent'.

* `key_val_separator`: The separator string to use between each setting name and value. Defaults to ' = ', but you could use this to override the default (e.g., whether or not the separator should include whitespace).

* `name`: An arbitrary name used as the identity of the resource.

* `path`: The INI file in which Puppet will ensure the specified setting.

* `provider`: The specific backend to use for this `ini_subsetting` resource. You will seldom need to specify this --- Puppet will usually discover the appropriate provider for your platform. The only available provider for `ini_subsetting` is ruby.

* `quote_char`: The character used to quote the entire value of the setting. Valid values are '', '"', and "'". Defaults to ''.

* `section`: The name of the INI file section in which the setting should be defined. Add a global section --- settings that appear at the beginning of the file, before any named sections --- by specifying a section name of "".

* `setting`: The name of the INI file setting to be defined.

* `subsetting`: The name of the INI file subsetting to be defined.

* `subsetting_separator`: The separator string used between subsettings. Defaults to " ".

* `value`: The value of the INI file subsetting to be defined.

##Limitations

This module is officially [supported](https://forge.puppetlabs.com/supported) on :

* Red Hat Enterprise Linux (RHEL) 5, 6, 7
* CentOS 5, 6, 7
* Oracle Linux 5, 6, 7
* Scientific Linux 5, 6, 7
* SLES 11 SP1 or greater
* Debian 6, 7
* Ubuntu 10.04 LTS, 12.04 LTS, 14.04 LTS
* Solaris 10, 11
* Windows Server 2003/2008 R2, 2012/2012 R2
* AIX 5.3, 6.1, 7.1

This module has also been tested, but is not officially supported, on:

* Red Hat Enterprise Linux (RHEL) 4
* Windows 7
* Mac OSX 10.9 (Mavericks)

##Development

Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can’t access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve.

We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.

You can read the complete module contribution guide on the [Puppet Labs wiki](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing).

##Contributors

The list of contributors can be found at: [https://github.com/puppetlabs/puppetlabs-inifile/graphs/contributors/contributors](https://github.com/puppetlabs/puppetlabs-inifile/graphs/contributors/contributors).


## 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 "".

4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppetlabs-inifile",
"version": "1.1.3",
"version": "1.1.4",
"author": "Puppet Labs",
"summary": "Resource types for managing settings in INI files",
"license": "Apache-2.0",
Expand Down Expand Up @@ -89,7 +89,7 @@
"requirements": [
{
"name": "pe",
"version_requirement": ">= 3.2.0 < 3.4.0"
"version_requirement": "3.x"
},
{
"name": "puppet",
Expand Down
11 changes: 6 additions & 5 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
require 'beaker-rspec/helpers/serverspec'

unless ENV['RS_PROVISION'] == 'no'
if hosts.first.is_pe?
install_pe
else
install_puppet
end
# This will install the latest available package on el and deb based
# systems fail on windows and osx, and install via gem on other *nixes
foss_opts = { :default_action => 'gem_install' }

if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end

hosts.each do |host|
if host['platform'] =~ /debian/
on host, 'echo \'export PATH=/var/lib/gems/1.8/bin/:${PATH}\' >> ~/.bashrc'
Expand Down

0 comments on commit db28fa2

Please sign in to comment.