Giter Club home page Giter Club logo

puppet-datacat's Introduction

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.

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.

puppet-datacat's People

Contributors

igalic avatar richardc avatar ymc-dabe avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.