templates/puppet/modules/manifests/mydef.pp.erb
################################################################################
# Time-stamp: <Wed 2017-08-23 14:37 svarrette>
#
# File:: <tt>mydef.pp</tt>
# Author:: <%= config[:author] %> (<%= config[:mail] %>)
# Copyright:: Copyright (c) <%= Time.now.year %> <%= config[:author] %>
# License:: <%= config[:license].capitalize %>
#
# ------------------------------------------------------------------------------
# == Defines: <%= config[:shortname] %>::mydef
#
# <%= config[:summary] %>
#
# == Pre-requisites
#
# * The class '<%= config[:shortname] %>' should have been instanciated
#
# == Parameters:
#
# [*ensure*]
# default to 'present', can be 'absent'.
# Default: 'present'
#
# [*content*]
# Specify the contents of the mydef entry as a string. Newlines, tabs,
# and spaces can be specified using the escaped syntax (e.g., \n for a newline)
#
# [*source*]
# Copy a file as the content of the mydef entry.
# Uses checksum to determine when a file should be copied.
# Valid values are either fully qualified paths to files, or URIs. Currently
# supported URI types are puppet and file.
# In neither the 'source' or 'content' parameter is specified, then the
# following parameters can be used to set the console entry.
#
# == Sample usage:
#
# include "<%= config[:shortname] %>"
#
# You can then add a mydef specification as follows:
#
# <%= config[:shortname] %>::mydef {
#
# }
#
# == Warnings
#
# /!\ Always respect the style guide available
# here[https://docs.puppet.com/puppet/latest/style_guide.html]
#
define <%= config[:shortname] %>::mydef(
$ensure = 'present',
$content = '',
$source = ''
)
{
validate_re($ensure, '^present$|^absent$')
#validate_string($mode)
#validate_hash($hash)
#validate_absolute_path($path)
#if ! (is_string($owner) or is_integer($owner)) {
# fail("\$owner must be a string or integer, got ${owner}")
#}
#validate_bool($replace)
include <%= config[:shortname] %>::params
# $name is provided at define invocation
$basename = $name
if ! ($ensure in [ 'present', 'absent' ]) {
fail("<%= config[:shortname] %>::mydef 'ensure' parameter must be set to either 'absent' or 'present'")
}
if ($<%= config[:shortname] %>::ensure != $ensure) {
if ($<%= config[:shortname] %>::ensure != 'present') {
fail("Cannot configure a <%= config[:shortname] %> '${basename}' as <%= config[:shortname] %>::ensure is NOT set to present (but ${<%= config[:shortname] %>::ensure})")
}
}
# if content is passed, use that, else if source is passed use that
$real_content = $content ? {
'' => $source ? {
'' => template('<%= config[:shortname] %>/<%= config[:shortname] %>_entry.erb'),
default => ''
},
default => $content
}
$real_source = $source ? {
'' => '',
default => $content ? {
'' => $source,
default => ''
}
}
# concat::fragment { "${<%= config[:shortname] %>::params::configfile}_${basename}":
# ensure => "${ensure}",
# target => "${<%= config[:shortname] %>::params::configfile}",
# content => $real_content,
# source => $real_source,
# order => '50',
# }
# case $ensure {
# present: {
# }
# absent: {
# }
# disabled: {
# }
# default: { err ( "Unknown ensure value: '${ensure}'" ) }
# }
}