Re: [Puppet Users] Include Hiera Classes

2018-08-15 Thread Helmut Schneider
Jo Rhett wrote:

> Well the exact answer to your question is:
> 
> lookup("roles::${category}::${class}::classes", Array,
> 'unique').include()
> 
> However, the code you've shown is implementing a hierarchy for class
> assignment duplicative of the Hiera hierarchy. Why not use Hiera's
> hierarchy to your advantage?
> 
> hiera.yaml:
>hierarchy:
> - name: "Role data"
>   path: "roles/%{facts.category}.yaml"
> 
> Then have an array named classes, and just use
> 
>   lookup('classes', Array, 'unique').include()
> 
> Much easier. Don't make your own hierarchy, make use of Hiera.

What is the difference / advantage of

hierarchy:
  - name: "Role data"
path: "roles/%{facts.category}.yaml"

and

hierarchy:
  name: "Role data"
  path: "roles/%{facts.category}.yaml"

-- 
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/xn0ldqofkfp40e001%40news.gmane.org.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] Include Hiera Classes

2018-08-08 Thread Jo Rhett
Well the exact answer to your question is:

lookup("roles::${category}::${class}::classes", Array, 'unique').include()

However, the code you've shown is implementing a hierarchy for class
assignment duplicative of the Hiera hierarchy. Why not use Hiera's
hierarchy to your advantage?

hiera.yaml:
   hierarchy:
- name: "Role data"
  path: "roles/%{facts.category}.yaml"

Then have an array named classes, and just use

  lookup('classes', Array, 'unique').include()

Much easier. Don't make your own hierarchy, make use of Hiera.

On Mon, Aug 6, 2018 at 6:22 AM Helmut Schneider  wrote:

> Hi,
>
> I want to include hiera classes.
>
> ---
> roles::webserver::apache::classes:
>   - my_apache
> roles::backup::bacula::classes:
>   - bacula
> roles::timeserver::ntpd::classes:
>   - ntpd
> roles::databaseserver::mysql::classes:
>   - mysqld
>
> I used to use the follwoing (ugly) code in nodes.pp to do so:
>
>   if ($roles) {
> $roles.each |$category, $classes| {
>   if ($classes) and (category) {
> $classes.each |$class| {
>   if ($class) {
> hiera_include ("roles::${category}::${class}::classes", {})
>   }
> }
>   }
> }
>   }
>
> Is there a better way e.g. using lookup?
>
> 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/xn0lddu4bbmleo000%40news.gmane.org
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CANsGaEoXH6fCnSaL9X%2B4cisFixOVVp00rzWOchBM5fyxiEnJgA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] Include Hiera Classes

2018-08-07 Thread Christopher Wood
Do yourself a favour, define puppet classes and resources in puppet code. There 
are surprisingly few people who can look at puppet resources in yaml and 
conceptualize which portion is causing that odd ruby+yaml error.

This is a useful model for how to lay that out:

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

If you keep only the most significant items in hiera it will be much easier to 
read. Albeit that it's older documentation, this section has the best phrasing 
I've found for this so far:

https://puppet.com/docs/pe/2016.4/r_n_p_full_example.html#the-rules-for-profile-classes

Quoth:

* If your business will always use the same value for a given parameter, 
hardcode it.
* If you can’t hardcode it, try to compute it based on information you already 
have.
* Finally, if you can’t compute it, look it up in your data. To reduce lookups, 
identify cases where multiple parameters can be derived from the answer to a 
single question.


(But maybe not hard-hardcode it, put it in a puppet variable or something.)

On Mon, Aug 06, 2018 at 01:19:45PM +, Helmut Schneider wrote:
> Hi,
> 
> I want to include hiera classes.
> 
> ---
> roles::webserver::apache::classes:
>   - my_apache
> roles::backup::bacula::classes:
>   - bacula
> roles::timeserver::ntpd::classes:
>   - ntpd
> roles::databaseserver::mysql::classes:
>   - mysqld
> 
> I used to use the follwoing (ugly) code in nodes.pp to do so:
> 
>   if ($roles) {
> $roles.each |$category, $classes| {
>   if ($classes) and (category) {
> $classes.each |$class| {
>   if ($class) {
> hiera_include ("roles::${category}::${class}::classes", {})
>   }
> }
>   }
> }
>   }
> 
> Is there a better way e.g. using lookup?
> 
> 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/xn0lddu4bbmleo000%40news.gmane.org.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/20180807164459.odzcrdocirljrcwv%40iniquitous.heresiarch.ca.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] Include Hiera Classes

2018-08-06 Thread Helmut Schneider
Hi,

I want to include hiera classes.

---
roles::webserver::apache::classes:
  - my_apache
roles::backup::bacula::classes:
  - bacula
roles::timeserver::ntpd::classes:
  - ntpd
roles::databaseserver::mysql::classes:
  - mysqld

I used to use the follwoing (ugly) code in nodes.pp to do so:

  if ($roles) {
$roles.each |$category, $classes| {
  if ($classes) and (category) {
$classes.each |$class| {
  if ($class) {
hiera_include ("roles::${category}::${class}::classes", {})
  }
}
  }
}
  }

Is there a better way e.g. using lookup?

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/xn0lddu4bbmleo000%40news.gmane.org.
For more options, visit https://groups.google.com/d/optout.