I'd like to get values from a specific hiera data file depending on a puppet variable. But I'm not sure I can do it. Let me explain in detail.
Imagine I have a puppet dsl file like this:
define arqjeer02::pe
(
$wlsdomain = 'wld-pre-02',
)
{
$wlsdomain_cfg = lookup( "I DON't KNOW HOW TO LOOK UP")
...
}
Anda hiera.yaml file like this in the module mymodule:
---
version: 5
defaults:
datadir: data
# data_hash: yaml_data
hierarchy:
- name: "Eyaml hierarchy"
lookup_key: eyaml_lookup_key
paths:
- "wlsdomains/%{wlsdomain}.eyaml" ##NOT SURE IF I HAVE TO MAKE SOME CHANGE HERE
- "wlsdomains/common.eyaml"
options:
pkcs7_private_key: "/etc/puppetlabs/puppet/keys/private_key.pkcs7.pem"
pkcs7_public_key: "/etc/puppetlabs/puppet/keys/public_key.pkcs7.pem"
and imagine I have the next data directory structure in the module:
data/wlsdomains/
data/wlsdomains/wld-pre-01.eyaml
data/wlsdomains/wld-pre-02.eyaml
data/wlsdomains/wld-pre-03.eyaml
data/wlsdomains/common.eyaml
where data/wlsdomains/wld-pre-02.eyaml looks like:
arqjeer02::pe::wlsdomain_cfg:
value1: 'a'
value2: 'b'
and
data/wlsdomains/common.eyaml looks like:
arqjeer02::pe::wlsdomain_cfg:
value1: 'z'
value2: 'y'
value3: 'x'
I'd like to lookup for arqjeer02::pe::wlsdomain_cfg in my puppet dsl file and get the hash value:
{ value1 => 'a', value2 => 'b', value3 => 'x', }
Any help?
A trace of a lookup:
puppet lookup "arqjeer02::pe::wlsdomain_cfg" --compile --environment production --node wl02-sns-t01-p0.msc.es
Debug: Lookup of 'arqjeer02::pe::wlsdomain_cfg'
Searching for "arqjeer02::pe::wlsdomain_cfg"
Global Data Provider (hiera configuration version 3)
Using configuration "/etc/puppetlabs/puppet/hiera.yaml"
Hierarchy entry "yaml"
Path "/etc/puppetlabs/code/environments/production/hieradata/nodes/wl02-sns-t01-p0.msc.es.yaml"
Original path: "nodes/%{::trusted.certname}"
Path not found
Path "/etc/puppetlabs/code/environments/production/hieradata/common.yaml"
Original path: "common"
No such key: "arqjeer02::pe::wlsdomain_cfg"
Module "arqjeer02" Data Provider (hiera configuration version 5)
Using configuration "/etc/puppetlabs/code/environments/production/site/arqjeer02/hiera.yaml"
Hierarchy entry "Eyaml hierarchy"
Path "/etc/puppetlabs/code/environments/production/site/arqjeer02/data/wlsdomains/.eyaml"
Original path: "wlsdomains/%{wlsdomain}.eyaml"
Path not found
Path "/etc/puppetlabs/code/environments/production/site/arqjeer02/data/wlsdomains/common.eyaml"
Original path: "wlsdomains/common.eyaml"
Found key: "arqjeer02::pe::wlsdomain_cfg" value: {
"value1" => "x",
"value2" => "y",
"value3" => "z",
"value4" => "we"
}
Hiera configuration recreated due to change of scope variables used in interpolation expressions
---
value1: x
value2: y
value3: z
value4: we
↧