Ask Your Question

Hiera automatic parameter lookup

asked 2016-08-03 15:21:08 -0600

alexseys gravatar image

Followed example here:

my "fqdn.yaml"

      - GROUP1
      - My-Custom-Group

my "init.pp"

class groups_allowed {

 $_sssd_config = $::realmd::sssd_config
 $_grps_allowed = hiera('users_allowed::adm_group')

On client after apply I get:

groups = [GROUP1, My-Custom-Group]

How can I remove square brackets from the string?

Thank you.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-08-04 21:32:48 -0600

kaizenCoder gravatar image

updated 2016-08-05 01:53:14 -0600

Have you looked at the stdlib module?


Joins an array into a string using a separator. For example, join(['a','b','c'], ",") results in: "a,b,c". Type: rvalue.

You should be able to do something like:

$_grps_allowed = join(hiera('users_allowed::adm_group'), ',');

edit flag offensive delete link more


This worked Thank you very much

alexseys gravatar imagealexseys ( 2016-08-05 08:40:00 -0600 )edit

@alexseys if this worked, please accept the answer

JohnsonEarls gravatar imageJohnsonEarls ( 2016-08-06 13:43:44 -0600 )edit

I would, but have no idea how to.

alexseys gravatar imagealexseys ( 2016-08-08 23:21:05 -0600 )edit

@alexseys: its the grey 'tick' below the down vote arrow.

kaizenCoder gravatar imagekaizenCoder ( 2016-08-15 20:15:12 -0600 )edit

answered 2016-08-03 17:53:51 -0600

DarylW gravatar image

What you are seeing is the string version of the array. Are you seeing that when you actually use it, or if you put it in a notify? If you use a notify, it will convert an array into a string. If you are using puppet 4.x, you can try iterating over it, if you are using puppet 3.x, you can pass it to a define/resource and see what is created..

notify{ $groups:
  message => 'You should see this for each member of the array',

You should be using AutomaticParameterLookup to actually assign the value to your parameter.

      - GROUP1
      - My-Custom-Group

Notice that we start the parameter with the name of the class, followed by the name of an actual parameter for that class. That's how Automatic paramterlookup works. It sees that in hiera, you have a key namespaced like groupsallowed::admgroup. When it looks at the classes it needs to instantiate, it sees a parameter without an explicit value for the class groupsallowed named admgroup, and will assign the value to it.

class groups_allowed (
  $adm_group, #This parameter will contain the array, via automatic parameter lookup, from the hiera configuration
) {

What you were previously doing was manually using a 'key' to look up a value from hiera. I'm not sure if when you do that lookup, if it will only return a string (depending on your version of puppet).

edit flag offensive delete link more


If you use a notify, it will convert an array into a string. If you are using puppet 4.x, you can try iterating over it, Thanks

googleclone gravatar imagegoogleclone ( 2016-08-05 05:44:09 -0600 )edit

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-08-03 15:21:08 -0600

Seen: 216 times

Last updated: Aug 05 '16