Forge Home

datacat

Puppet type for handling data fragments

6,424,033 downloads

5,845,866 latest version

4.4 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Support the Puppet Community by contributing to this module

You are welcome to contribute to this module by suggesting new features, currency updates, or fixes. Every contribution is valuable to help ensure that the module remains compatible with the latest Puppet versions and continues to meet community needs. Complete the following steps:

  1. Review the module’s contribution guidelines and any licenses. Ensure that your planned contribution aligns with the author’s standards and any legal requirements.
  2. Fork the repository on GitHub, make changes on a branch of your fork, and submit a pull request. The pull request must clearly document your proposed change.

For questions about updating the module, contact the module’s author.

Version information

  • 0.6.2 (latest)
  • 0.6.1
  • 0.6.0
  • 0.5.0
  • 0.4.3
  • 0.4.2
  • 0.4.1
  • 0.4.0
  • 0.3.0
  • 0.2.1
  • 0.2.0
  • 0.1.0
  • 0.0.3
  • 0.0.2
  • 0.0.1
released Aug 16th 2015

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'richardc-datacat', '0.6.2'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add richardc-datacat
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install richardc-datacat --version 0.6.2

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download
Tags: file, concat, data, merge

Documentation

richardc/datacat — version 0.6.2 Aug 16th 2015

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.

Build Status

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.