Skip to content

Hiera Support #45

Closed
Closed

Description

@ruedigerblock

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

Activity

  1. self-assigned this
    on Feb 2, 2015
  2. esalberg commented on Aug 24, 2015

    @esalberg
    Contributor

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

  3. razorsedge commented on Oct 7, 2015

    @razorsedge
    Owner

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

  4. razorsedge commented on Oct 7, 2015

    @razorsedge
    Owner

    @esalberg See commit 1ee64aa.

  5. esalberg commented on Oct 7, 2015

    @esalberg
    Contributor

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

  6. razorsedge commented on Oct 7, 2015

    @razorsedge
    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.

  7. esalberg commented on Oct 7, 2015

    @esalberg
    Contributor

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

  8. esalberg commented on Oct 7, 2015

    @esalberg
    Contributor

    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.

  9. esalberg commented on Oct 8, 2015

    @esalberg
    Contributor

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

  10. chrisdaish commented on Jan 15, 2016

    @chrisdaish

    Hi chaps,

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

    Chris

  11. razorsedge commented on Mar 12, 2016

    @razorsedge
    Owner

    #78 has been merged.

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

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions