I'm trying to load a hiera file according to a specific flag.
Hiera hierarachy configuration is
:hierarchy:
- "%{environment}/%{::fqdn}"
- "%{environment}/%{nodetype}"
- "%{environment}/%{calling_module}"
- "%{environment}"
- "common/%{calling_module}"
- "common"
In fact in want to factorize some configuration at the "nodetype" level. Goal is to avoid putting the same hiera "block" inside files:
- environment/test/myhost1.example.com.yaml
- environment/test/myhost2.example.com.yaml
- environment/test/myhost3.example.com.yaml
but instead but common part in :
- environment/test/nfs-server.yaml for all nfs servers related common configuration
- environment/test/backend-server.yaml for all backend servers related common
After that all servers would get their own specific values with the fqdn yaml file. (this part is ok)
Currently, i don't know how to provide the "nodetype" data to hiera context.
I tried to put it into the main manifest file like (yeah I read the doc and I know it a bad idea but even with despair attempt, it don't work anyway)
node 'nfs1.example.com', 'nfs2.example.com' {
$nodetype= 'nfs-server'
but the file environment/test/nfs-server.yaml is not loaded by hiera.
I also tried to use custom fact but using a custom fact with
modules/hosts/facts.d/host-fact-test.txt
File is send to the host of the agent but again here, hiera don't use the dedicated file.
Notice: /File[/var/lib/puppet/facts.d/host-fact-test.txt]/ensure: defined content as '{md5}d7492faae1bfe55f65f9958a7a5f6df9'
If I use a notify puppet command, the value is ok
if $nodetype== 'nfs-server' {
notify {"Running with \$nodetype ${nodetype} ID defined":
withpath => true,
}
}
result:
Notice: /Stage[main]/attemps/Notify[Running with $nodetype nfs-server ID defined]/message: Running with $nodetype nfs-server ID defined
Stack is Puppet opensource on Ubuntu 14 so versions are:
- puppet 3.8.4
- hiera 1.3.4
- facter 2.4.4
Any idea or suggestion to make it work (or achieve a similar behavior) ?
The Puppet master process usually does not use the configuration in
/etc/hiera.yaml
, which can be confusing. With Puppet3.x
, it's usually/etc/puppet/hiera.yaml
.You can make sure using (as root)
on the master machine.