Ask Your Question

iteration and repetition through hiera hashes in puppet 2016.1

asked 2016-07-08 10:34:24 -0600

gilbo gravatar image

updated 2016-07-08 11:10:36 -0600

ramindk gravatar image

HI All

i've defined a hash like so:

    gid: 1203

and i'm trying to create a generic profiles which will create a unix group from that. i'm trying to prize myself away from create_resources by doing this:

class profiles::groups (
) {

  $groups_to_create.each |String $group| {
    group { $group:
      * => $group

so should that work? it doesn't at the moment as i get this:

Error 400 on SERVER: Syntax error at '=>' at /etc/puppetlabs/code/environments/tibcotommy/site/profiles/manifests/groups.pp:10:7

it's really because I'm refactoring everything for puppet 2016.1 and I'm led to believe that create_resources is old skool and will probably become defunct. I've read reams and reams of documentation and examples of iteration but admittedly i can't find anything definitive for iterating through a hash with a method other than create_resources.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-07-11 03:39:54 -0600

gilbo gravatar image

Thanks Lupin but that didn't quite work. It did however lead me to this which does seem to work quite nicely:

$groups_to_create.each |$name, $group| {
    group { "$name":
     * => $group,
edit flag offensive delete link more

answered 2016-07-08 15:30:30 -0600

lupin gravatar image

Try this.

  $groups_to_create.each |  $group| {
    group { "$group":
      ensure  => 'present',
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-07-08 10:34:24 -0600

Seen: 255 times

Last updated: Jul 11 '16