0

Need some help thinking.

I have 200 servers and have to apply a specific configuration to 100.

The only thing they share in common is the name prefix: they all start with zmb-

hiera.yaml

---
:backends:
  - yaml

:yaml:
  :datadir:

:hierarchy:
  - "nodes/pro/%{::trusted.certname}"
  - "nodes/hom/%{::trusted.certname}"
  - "nodes/%{::trusted.certname}"
  - "%{::os.family}"
  - common

:logger: puppet

What should i change in :hierarchy: ?


puppet version: 4.10.10


We need more information here, to understand what the data is you are sending to your 100 nodes, and why you believe this is a data problem, i.e. a problem to be solved in Hiera rather than in your Puppet manifests. - Alex Harvey

A very simple example to get things going:

until yesterday all nodes had the same NTP server, 10.1.1.1
this was set by the class ntp, which reads the values from common

common.yaml

---
classes:
    - base
    - ntp

ntp::server: '10.1.1.1'

ntp/init.pp

class ntp ($server) {
    ...
}

Now, today, i want to change the IP to 10.1.1.99 for 100 servers, and they all have their hostnames starting with zmb-

My question is: how?

Matthew Schuchard
  • 25,172
  • 3
  • 47
  • 67
RASG
  • 5,988
  • 4
  • 26
  • 47
  • We need more information here, to understand what the data is you are sending to your 100 nodes, and why you believe this is a data problem, i.e. a problem to be solved in Hiera rather than in your Puppet manifests. – Alex Harvey Mar 14 '18 at 21:06
  • @AlexHarvey edited the question – RASG Mar 15 '18 at 12:38

1 Answers1

2

There is no way to use a regular expression match (as far as I am aware, and as far as I can tell) in a Hiera hierarchy definition.

You would need to firstly create a custom fact. For example, you could write:

Facter.add(:host_code) do
  setcode do
    Facter.value(:hostname).slice(0..2)
  end
end

Then you could add a level:

:hierarchy:
  - "nodes/%{::host_code}" # here
  - "nodes/pro/%{::trusted.certname}"
  - "nodes/hom/%{::trusted.certname}"
  - "nodes/%{::trusted.certname}"
  - "%{::os.family}"
  - common

Then create a file hieradata/nodes/zmb.yaml.

Of course, I would question that a fact based on the first three letters of the host name is a well-designed fact. What is it about those 100 nodes that causes them to have a hostname zmb-? The answer to that question probably gives you the proper basis of your new fact.

Alex Harvey
  • 14,494
  • 5
  • 61
  • 97
  • you are 100% right! i should focus on why they are grouped/prefixed with `zmb-`. they probably share more than just the name, and the setting i have to change can be configured somewhere else. i got exactly what i came looking for. thank you for your time. – RASG Mar 15 '18 at 16:43
  • 1
    Custom fact based on hostname that is defined as a hierarchy level is definitely the quickest/safest path to success here. The suggestion for doing robust `role` definitions and grouping by that instead should definitely be considered too, and it sounds like @RASG recognizes that. – Matthew Schuchard Mar 15 '18 at 17:55