0
votes

I have a node 1 on which my application is going to be deployed using puppet. I have created a hiera file (node1_application.yaml) which states all the server details that this application is going to use such as

ldap_server = node2

mq_server = node3

Is there any way that in node.pp , I only give node1 information which stats which class to be applied on node 1. Then this class reads my hiera file and see that ldap server is on node 2 so ldap module should be applied on node 2.

It should be dynamically decided using my hiera file that which class should be applied on which node. Is it possible to do?

I am using puppet enterprise, hiera, facter, puppetdb and mcollective.

5

5 Answers

2
votes

I think is better to use hiera_include('classes')

If you have node01.example.com.yaml now you can write something like this:

---
classes:
  - base
  - ldap

Now in node01.example.com.pp:

node 'node01.example.com' {
      hiera_include('classes')
}
1
votes

Yes, it's possible.

node default{
    if hiera("useldap") == 'true' {
      include ldap
    }
}

Will install ldap in every node that resolves useldap = true

1
votes

You cannot do it that way. You have to define within node2 that ldap class has to be included. It cannot be "deducted" by class/hiera in node1, since those are parsed independenly when applying changes to those particular nodes.

1
votes

I will recommended a newer solution, where nodes separate each role (if puppetmaster < 4.0).

Now, manifests/database.pp:

node /^(projectnameinthreechar)-([a-z]{3})-db([\d]+)\./ {
    class {
            "server::project::db":
                    ;
    }
}


class server::project::db ($paramteres) { ... }

Matching all node, who host names cathing this pattern:

 /^(projectnameinthreechar)-([a-z]{3})-db([\d]+)\./

Example:

web-can-db01
1
votes

Yes you can.

You should do the following.

site.pp:

node default{
  hiera_include('classes')
}

hiera.yaml:

---
:backends:
  - yaml

:yaml:
  :datadir: "/etc/puppetlabs/code/environments/{::environment}/hieradata"

:hierarchy:
  - "nodes/%{::trusted.certname}"
  - "common"

And then under hieradata you should have nodes directory which contains

node01.domain.com.yaml:

---
classes:
  - base
  - application

node02.domain.com.yaml:

---
classes:
  - base
  - ldap