includable
Version information
Start using this module
Add this module to your Puppetfile:
mod 'geoffwilliams-includable', '0.2.0'
Learn more about managing modules with a PuppetfileDocumentation
includable
Table of Contents
- Description
- Usage - Configuration options and additional functionality
- Limitations - OS compatibility, etc.
- Development - Guide for contributing to the module
Description
Provide the includable()
function to test whether a class has been written and is in the path or not
Usage
includable()
Test whether the class definition for the passed in class name is exists in the environment currently being evaluated.
For example, given:
/etc/puppetlabs/code/environments/production/modules/mock_profile/
└── manifests
└── myprofile.pp
includable('mock_profile::myprofile') # true
includable('mock_profile::not_here') # false
Classes will be resolved according the modulepath
for the current environment according to Puppet. See function
source code for exact implementation details
Limitations
- Not supported by Puppet, Inc.
Development
PRs accepted :)
Testing
This module supports testing using PDQTest.
Test can be executed with:
bundle install
make
See .travis.yml
for a working CI example
Reference
Table of Contents
Functions
includable
: Test if a puppet class file exists and can be included
Functions
includable
Type: Ruby 4.x API
Function to detect whether it is possible to include a given puppet class or not based on whether the class file exists. The intended usage of this is to allow lazy creation of role classes:
The reason for this is that Puppet deployers may want to assign roles to particular nodes without immediately having to create the associated role class. This removes the need for up-front work creating role classes that are TODO and the need to regenerate certificates once a suitable role class becomes available.
Function is environment aware. There is an undocumented private API for puppet which could be used to hook into Puppet internals and test for class existance, however this API is subject to change without notice and this would entirely break classification if used as the example above suggests. Instead, we convert the class name into a string and attempt to match a regular expression defining the class inside it. If this matches the intention of the user was probably to write a class, although we make no claims as to its validity and subsequent inclusion will fail if there are syntax errors.
includable(String $classname)
Function to detect whether it is possible to include a given puppet class or not based on whether the class file exists. The intended usage of this is to allow lazy creation of role classes:
The reason for this is that Puppet deployers may want to assign roles to particular nodes without immediately having to create the associated role class. This removes the need for up-front work creating role classes that are TODO and the need to regenerate certificates once a suitable role class becomes available.
Function is environment aware. There is an undocumented private API for puppet which could be used to hook into Puppet internals and test for class existance, however this API is subject to change without notice and this would entirely break classification if used as the example above suggests. Instead, we convert the class name into a string and attempt to match a regular expression defining the class inside it. If this matches the intention of the user was probably to write a class, although we make no claims as to its validity and subsequent inclusion will fail if there are syntax errors.
Returns: Any
true if include classname
should succeed, otherwise false if the class is missing from
the filesystem
classname
Data type: String
Name of the class to test for incudability (existance as a file on the master)