Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hiera Support #45

Closed
ruedigerblock opened this issue Sep 9, 2014 · 10 comments
Closed

Hiera Support #45

ruedigerblock opened this issue Sep 9, 2014 · 10 comments
Assignees

Comments

@ruedigerblock
Copy link

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

@razorsedge razorsedge self-assigned this Feb 2, 2015
@esalberg
Copy link
Contributor

I am doing something similar to this as well. Would it be helpful to put in a pull request?

@razorsedge
Copy link
Owner

Mentioned in #69, #18, and #10.

@razorsedge
Copy link
Owner

@esalberg See commit 1ee64aa.

@esalberg
Copy link
Contributor

esalberg commented Oct 7, 2015

@razorsedge - That commit is just a doc change / no code, or am I missing something?

@razorsedge
Copy link
Owner

@esalberg Perhaps throw that commit and ee9aa2b into a PR? Touch things up a bit like we discussed (ie hiera.pp and not init.pp)?

At least it might be a good starting point.

@esalberg
Copy link
Contributor

esalberg commented Oct 7, 2015

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)
}
}

@esalberg
Copy link
Contributor

esalberg commented Oct 7, 2015

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.

@esalberg
Copy link
Contributor

esalberg commented Oct 8, 2015

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).

@chrisdaish
Copy link

Hi chaps,

Any news on the recent PR (#78)?
Would be great to get see this implemented into the module.

Chris

@razorsedge
Copy link
Owner

#78 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants