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

2019-07-22 Thread Helmut Schneider
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!

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/xn0lwqh7y7j1qws000%40news.gmane.org.


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

2019-07-22 Thread Christopher Wood
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.

On Mon, 2019-07-22 at 11:45 +, Helmut Schneider wrote:
> 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.yam
> l
> 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!
> 

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/2bde02fcb3cdb5167d28f492cc0b43b446557fd0.camel%40pobox.com.


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

2019-07-22 Thread Helmut Schneider
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.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/xn0lwqkg17nfd95001%40news.gmane.org.


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

2019-07-22 Thread Bart-Jan Vrielink
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



 


-Original message-
From: Helmut Schneider 
Sent: Monday 22nd July 2019 15:48
To: puppet-users@googlegroups.com
Subject: Re: [Puppet Users] [EPP] Using tagged, defined, a better way to create 
variables, ... to verify if a class is included


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.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/xn0lwqkg17nfd95001%40news.gmane.org.


-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/zarafa.5d35c154.13bc.3b6adc4113070289%40anjie.dontpanic.nl.