Hiera Support
Closed this issue · 10 comments
Hi,
I plan to use hiera for class assosiation in the future. Hiera does not allow calls to puppet defines, but it can be used with the create_resource function.
What I did to make it work is to create a manifest in your network module on my puppetmaster and include this is the nodes hiera file. What it does is simply to ask hiera for a hash containing data about interfaces and realizes them.
class network::hiera {
$resources = ['network::bridge::static', 'network::if::bridge']
define resource() {
$interfaces = hiera_hash($title,false)
if $interfaces {
create_resources($title,$interfaces)
}
}
network::hiera::resource {$resources:}
}
A hiera yaml file looks like this:
network::bridge::static: { "br0": { ensure: "up", ipaddress: "XXX.XXX.XXX.XXX", netmask: "255.255.255.128", stp: true, delay: "0", bridging_opts: "priority=65535" }}
network::if::bridge: { "em1": { ensure: "up", bridge: "br0" }}
I will include the remaining resources in the array and then one should be able to make use of your network module with hiera. At least I will.
regards,
Rüdiger Block
I am doing something similar to this as well. Would it be helpful to put in a pull request?
@razorsedge - That commit is just a doc change / no code, or am I missing something?
Here's what I've been working on so far. I started using Saz's puppet-ssh code as inspiration, but I think we can simplify with the decision to create a new hiera.pp file instead of putting the hiera_hash entries into init.pp. I'm hoping that means we can remove the pass-in parameters and checks for undef (since if the hiera entries are undef, they should still be handled via the default module method).
I'm hoping that Option #2 (simplified) will work, but I need to test it with no hiera entry / passing in from code as well. It should work for hiera only and no entry in hiera.
Once this has been finalized, it's just a matter of duplicating another 10-15 times for all the defines.
This is what I have so far (for a single define):
----- Option #1: With parameters / extra checks ---------
class network::hiera (
$network_alias = {},
) {
validate_hash($network_alias)
Merge hashes from multiple hiera layers
$hiera_network_alias = hiera_hash('network::alias', undef)
$fin_network_alias = $hiera_network_alias ? {
undef => $network_alias,
default => $hiera_network_alias,
}
create_resources('network::alias', $fin_network_alias)
}
--------Option #2: Simplified ---------
class network::hiera {
Merge hashes from multiple hiera layers
$hiera_network_alias = hiera_hash('network::alias', undef)
if $hiera_network_alias {
create_resources('network::alias', $hiera_network_alias)
}
}
I just re-read the ticket, and instead of duplicating, the original resources array is a much more efficient code structure, so I would try that.
Quick update on testing:
With "include network::hiera" in my network.pp and simplified hiera.pp code in the module:
- Works correctly with data either in hiera or in code.
- With different entries in code and hiera, Puppet does both (e.g. for network::alias, both eth0:1 and eth0:2).
- With the same entry in both code and hiera, Puppet throws a duplicate definition error (as desired).
I think this looks good - I'm going to expand it out to the other defines, update docs, and make a PR (hopefully before EOD tomorrow).
Hi chaps,
Any news on the recent PR (#78)?
Would be great to get see this implemented into the module.
Chris
#78 has been merged.