Version information
Start using this module
Add this module to your Puppetfile:
mod 'richardc-datacat', '0.6.2'
Learn more about managing modules with a PuppetfileDocumentation
Puppet types for concatenating data via a template
The datacat
and datacat_fragment
types allow you to build up a data
structure which is rendered using a template. This is similar to some of the
common concatenation patterns though the intent should be clearer as it pushes
the boilerplate down into the type.
Sample Usage
datacat { '/etc/nagios/objects/hostgroups.cfg':
template => "${module_name}/hostgroups.cfg.erb",
}
datacat_fragment { "${::fqdn} in device hostgroup":
target => '/etc/nagios/objects/hostgroups.cfg',
data => {
device => [ $::fqdn ],
},
}
# fred.dc1.notreal has an ilo fred-ilo.dc1.notreal
$ilo_fqdn = regsubst($::fqdn, '\.', '-ilo.')
datacat_fragment { "${ilo_fqdn} in device hostgroup":
target => '/etc/nagios/objects/hostgroups.cfg',
data => {
device => [ $ilo_fqdn ],
},
}
And then in your hostgroups.cfg.erb
# hostgroups.cfg.erb
<% @data.keys.sort.each do |hostgroup| %>
define hostgroup {
name <%= hostgroup %>
members <%= @data[hostgroup].sort.join(',') %>
}
<% end %>
Will produce something like:
# /etc/nagios/objects/hostgroups.cfg
define hostgroup {
name device
members fred.dc1.notreal,fred-ilo.dc1.notreal
}
There are additional samples in a blog post I wrote to describe the approach, http://richardc.unixbeard.net/2013/02/puppet-concat-patterns/
Types and Definitions
Defined Type: datacat
Wraps the datacat_collector
and file
types to cover the most common
use-case, collecting data for and templating an entire file.
The ensure
parameter defaults to file
(an alias for present
). ensure
can be set to absent
. In that case datacat
will make sure the file does
not exist and will not collect anything with datacat_collector
.
Type: datacat_collector
The datacat_collector
type deeply merges a data hash from
the datacat_fragment
resources that target it.
These fragments are then rendered via an erb template specified by the
template_body
parameter and used to update the target_field
property
of the related target_resource
.
Sample usage:
datacat_collector { 'open_ports':
template_body => '<%= @data["ports"].sort.join(",") %>',
target_resource => File_line['open_ports'],
target_field => 'line',
}
datacat_fragment { 'open webserver':
target => 'open_ports',
data => { ports => [ 80, 443 ] },
}
datacat_fragment { 'open ssh':
target => 'open_ports',
data => { ports => [ 22 ] },
}
Caveats
The template is evaluated by the agent at the point of catalog evaluation,
this means you cannot call out to puppet parser functions as you would when
using the usual template()
function.
Copyright and License
Copyright (C) 2013 Richard Clamp
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Types in this module release
0.6.2 Sunday 16th August, 2015
Corrected template_body
error message when template is missing
(Github #26 - Robin Bowes)
Converted Metadata to metadata.json (Github #23 - Bram Vogelaar)
0.6.1 Tuesday 23rd September, 2014 Fix usage with the future parser (Github #16 - Oscar Ferrer)
0.6.0 Monday 16th June, 2014 Add ensure to the datacat define (Github #13 - Igor Galić)
0.5.0 Saturday 10th May, 2014 Add show_diff to the datacat define for parity with the file type in puppet 3.2 and onwards (Github #10 - Sebastian Schmidt)
0.4.3 Saturday 5th April, 2014 Change the README.md back to github-flavoured markdown as the forge supports this now (Github #6 - Igor Galić) Fix for compatibilty with puppet 3.5.0 (Github #7 - Daniel Beyer)
0.4.2 Thursday 26th September, 2013 Fix for catalog changes in 3.3.0 when using master/agent (Github #4)
0.4.1 Thursday 8th August, 2013
Changes datacat
define to name the wrapped file
resource with the
$title of the resource itself.
0.4.0 Thursday 25th July, 2013
Added source_key
parameter to datacat_collector, to allow bypassing the
templating step.
0.3.0 Tuesday 9th July, 2013 Add collects parameter to the datacat_collector type, for acts-as relationships.
0.2.1 Monday 8th July, 2013 Bugfix - when modifying the datacat_collector map on path the File should still match to $path
0.2.0 Monday 8th July, 2013 Allow the target parameter of a datacat_fragment to be an array to target multiple collectors. The datacat_collector wrapped by the datacat type will now be named for the resource rather than the file path.
0.1.0 Friday 5th July, 2013 Add a order parameter to the datacat_fragment type for relative ordering of fragment merging. Exposed the datacat_collector type and allow it to be used for updating more than just the file type's content parameter.
0.0.3 Wednesday 26th June, 2013 Reworked the behaviour of datacat_collector to only refresh the resource when the output from the template evaluation changes. (Github #3)
0.0.2 Tuesday 16th April, 2013 Changed README.md from Github flavored markup to standard markdown to make the forge happier.
0.0.1 Tuesday 16th April, 2013 Initial forge release