puppethiera

Create system group from hiera


is it possible to create a system group from hiera? I know how to create a system group in the manifest via class, but I have failed to move that to hiera

Any example of creating a systemgroup "foo" with gid "1000" in hiera would be highly appreciated.

Thanks


Solution

  • Hiera is a data service. It can provide data about system groups, or about any kind of resource at all, but you need at least a little bit of manifest code somewhere to make a resource declaration out of that. For example, this pushes all the details out of the manifest and into Hiera (or other manifest code):

    class mymodule::groups(Hash[String, Hash] $groupdata) {
        $groupdata.each |$gname, $params| {
            group { $gname: * => $params }
        }
    }
    

    Hiera data feeding that class might look something like this:

    mymodule::groups::groupdata:
      group1:
        system: true
      group2:
        gid:    42
        system: true
      group3:
        ensure: absent
    

    The value for $groupdata is, as declared by the class, a Hash of Hashes. The keys are group names, and the values are hashes of property names and values for the built-in Group resource type.

    There are many other ways that one could accomplish this, with different advantages and disadvantages. I present this one because it is among the simplest.