Forge Home

yamlresource

Puppet module that adds the yamlresource face

7,681 downloads

2,167 latest version

5.0 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.

Version information

  • 0.2.2 (latest)
  • 0.2.1
  • 0.1.0
released Jan 26th 2020
This version is compatible with:
  • Puppet Enterprise 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x, 2018.1.x, 2017.3.x, 2017.2.x, 2016.4.x
  • Puppet >= 4.10.0 < 7.0.0
  • , ,

Start using this module

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

Add this module to your Puppetfile:

mod 'ffrank-yamlresource', '0.2.2'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add ffrank-yamlresource
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install ffrank-yamlresource --version 0.2.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: face, resource, yaml

Documentation

ffrank/yamlresource — version 0.2.2 Jan 26th 2020

puppet-yamlresource

Build Status

A puppet face similar to puppet resource, with the ability to accept structured data for input.

Motivation

The puppet resource command is very useful to manage single resources without the overhead of writing it in manifest form, and running the catalog builder. However, it can only accept a limited subset of Puppet's supported attribute values. For example:

cron { 'renew-lease':
  ensure => present,
  command => '/usr/local/bin/renew-lease',
  user => 'root',
  minute => 10,
  hour => 13,
}

This resource can be applied a little more simply with the following command:

puppet resource cron renew-lease ensure=present command=/usr/local/bin/renew-lease user=root minute=10 hour=13

Now consider the following change:

cron { 'renew-lease':
  # ...
  hour => [ 1, 13 ],
}

This resource cannot be represented in puppet resource syntax, because array values like [ 1, 13 ] are not recognized.

With puppet yamlresource, you can use the following command:

puppet yamlresource cron renew-license \
    '{ ensure: present, command: /usr/local/bin/renew-lease, user: root, minute: 10, hour: [ 1, 13 ], }'

Note that the attributes are actually passed in a JSON-like syntax, but that's fine because JSON is valid YAML, and YAML even gives you a lot of freedom, such as optional quotes, trailing commas etc.

Installation

puppet module install ffrank-yamlresource

Usage

From the command line

  1. List all resources of a given type

    puppet yamlresource cron
    
  2. Show a YAML representation of a distinct resource

    puppet yamlresource cron renew-lease
    
  3. Manage the state of a single resource

    puppet yamlresource cron renew-lease '<YAML data>'

Through the Ruby API

The functionality is available through Puppet's faces API. Documentation is yet to be created.

Receive mode

Receive mode gives Puppet greater utility as a worker back-end for other software.

The puppet yamlresource receive subcommand takes no other parameters. When invoked, Puppet starts reading resource descriptions from the command line. It tries and applies each of these resources. It always prints one line of JSON in return. Any errors are reported in this JSON structure.

This is a typical, successful interaction with the running instance of yamlresource receive:

file /tmp/x { ensure: file }
{"resource":"File[/tmp/x]","failed":false,"changed":true,"noop":false,"error":false,"exception":null}

Issues are indicated through the error and exception fields:

file /tmp/y { parameters: many }
Error: (Applying File[/tmp/z]) no parameter named 'parameters'
{"failed":true,"changed":false,"error":true,"exception":"no parameter named 'parameters'"}

This input format only works for resources without spaces in the resource title. A more robust input format is also JSON (wrapping the YAML parameters in a string):

{"type":"file", "title":"/tmp/z", "params":"{ ensure: file }"}
{"resource":"File[/tmp/z]","failed":false,"changed":true,"noop":false,"error":false,"exception":null}`

This is quite cumbersome on the shell, but more reliable when integrating other software.