1

So I have Foreman set up, and would like to pass in a parameter that is basically a way to easily specify users and groups that can log in as that user. My idea is currently to have the parameter take this sort of input:

user1;group1,group2,group3.user2;group1,groupn.user3;group1

Normally (in other languages), I'd make a 2 dimensional array and then loop through it. This isn't really something that can be done in Puppet though.

I've written a custom function to expand out the group members, and then pass that into the k5login type. My next thought is to create a defined type for that. I'm just not sure if I can pass in 2 values... And am I re-inventing the wheel, or am I doing something sort of stupid here?

  • Is there a reason you would not use data structured as hashes and arrays? Such as { user1 => [ group1, ... ], user2 => ... } – Felix Frank Apr 27 '14 at 18:37
  • I'm not sure if I can pass a hash / array as a parameter from The Foreman? – jmp242 Apr 28 '14 at 14:16
0

Sounds like you want the "flatten" function from puppet-stdlib.

This function flattens any deeply nested arrays and returns a single flat array
as a result.

*Examples:*

    flatten(['a', ['b', ['c']]])

Would return: ['a','b','c']

https://github.com/puppetlabs/puppetlabs-stdlib

We use it to do something like this:

$flattened = join(unique(sort(flatten([$host_array1,$host_array2,$host_array3]))), ',' )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.