[EPP] Using tagged, defined, a better way to create variables, ... to verify if a class is included

21 views
Skip to first unread message

Helmut Schneider

unread,
Jul 22, 2019, 11:45:46 AM7/22/19
to puppet...@googlegroups.com
Hi,

I hope I can descripe the challenge.

/etc/puppetlabs/code/environments/production/manifests/nodes.pp:
node default {
include common
}

/etc/puppetlabs/code/modules/common/manifests/init.pp:
class common inherits config {
include $classes
[...]

/etc/puppetlabs/code/modules/config/manifests/init.pp:
class config {
$classes = lookup({
"name" => "classes",
"merge" => {
"strategy" => "deep",
"knockout_prefix" => "--",
},
"default_value" => [],
})

/etc/puppetlabs/code/modules/bacula/templates/etc/bacula/fileset-exclude
.epp
<%- | Hash $packages,
Array $classes
| -%>
<% if !empty(grep($packages['install'], "amavis")) or
!empty(grep($classes, "amavis")) { -%>



But I'm also using roles:

/etc/puppetlabs/code/environments/production/hieradata/nodes/node.yaml
roles:
mailserver:
- amavisd
vpn:
- openvpn
webserver:
- apache

/etc/puppetlabs/code/environments/production/hieradata/roles.yaml:
role_details:
mailserver:
amavisd:
classes:
- amavisd
- clamav
- spamassassin

To include all role classes I do:

/etc/puppetlabs/code/modules/common/manifests/init.pp:
class common inherits config {
include $classes

if ($roles) {
$roles.dig.keys.each |String $role| {
$roles[$role].each |String $application| {
$roleClasses = lookup({"name" =>
"role_details.${role}.${application}.classes", "merge" => "deep",
"default_value" => undef})
if ($roleClasses) {
include $roleClasses
}
}
}
}

As I did not find a way put all role-classes to a single variable
(e.g.$roleClasses) I tried to do this in the epp:

<%= tagged("amavisd") %>

It resolves to false. Always.

Does anyone see a way to put all roleClasses into a single variable or
make "tagged" work in the epp or any other way to solve this? I know
the concept of Puppet but there are sometimes challenges where just
describing a state is not sufficient. :)

[helmut@BSDHelmut ~]$ puppet -V
5.5.14
[helmut@BSDHelmut ~]$

Thank you!

Christopher Wood

unread,
Jul 22, 2019, 12:35:21 PM7/22/19
to puppet...@googlegroups.com
Top post, I'm not skilled enough to read this hence not sure where I'd
interject. You may be better off using simpler constructs so that
people with a wider variety of skill levels in your organization can
contribute.

What problems are you encountering where describing state is not
sufficient to correctly configure a host?

We're using the roles/profiles model, with 1 role per host, and
multiple profiles in that role. Keeping the two-step approach helps us
assign roles more clearly. Also see:

https://www.craigdunn.org/2012/05/239/

https://puppet.com/docs/pe/2019.1/the_roles_and_profiles_method.html

The way this goes here is that in site.pp we have:

include role::${::role}

That variable $::role is set in the ENC:

https://puppet.com/docs/puppet/6.6/nodes_external.html

The role class is like:

class role::myrole {
include profile::firstprofile
include profile::moregenericprofile
}

The profile class is like:

class profile::firstprofile (
String $requiredparam,
String $optionalparam = 'default text',
) {
class { 'myclass':
attribute => $requiredparam,
}
# etc.
}

This way people can figure out what classes go where, and which hiera
keys interpolate into which configs, without reading the catalog or
unfolding logic in their heads.

Helmut Schneider

unread,
Jul 22, 2019, 1:48:17 PM7/22/19
to puppet...@googlegroups.com
Christopher Wood wrote:

> Top post, I'm not skilled enough to read this hence not sure where I'd
> interject. You may be better off using simpler constructs so that
> people with a wider variety of skill levels in your organization can
> contribute.
>
> What problems are you encountering where describing state is not
> sufficient to correctly configure a host?

I need to put "/var/amavis" into a configuration file (only) if amavisd
is installed. So I'm either looking for a way to do a lookup with
wildcards

$roleClasses = lookup({"name" => "role_details.*.*.classes", "merge" =>
"deep", "default_value" => undef})
[...]
<% if !empty(grep($roleClasses, "amavisd")) { -%>

or to pass tags to an epp template:

<% if tagged("amavisd") %>

If I put "/var/amavis" into this configuration file and amavisd is not
installed it throws an error.

Bart-Jan Vrielink

unread,
Jul 22, 2019, 1:59:58 PM7/22/19
to puppet...@googlegroups.com

Hello,


Looks like the concat module may do the job?


$my_template = '/my/config.file'

concat { $my_template:

}


concat::fragment { 'standard contents':

  target => $my_template,

  content => template('my.epp'),

}


And then in the Amavis profile class:


concat::fragment { 'extra special contents':

  target => $my_template,

  content => '/var/lib/amavis',

}


Add any other fragments you'd like, and of course any other options you need. See https://forge.puppet.com/puppetlabs/concat


 


-- 
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/xn0lwqkg17nfd95001%40news.gmane.org.

Reply all
Reply to author
Forward
0 new messages