Concatinating hashes

30 views
Skip to first unread message

Michael Wörz

unread,
Jan 9, 2015, 8:09:49 AM1/9/15
to puppet...@googlegroups.com
Hello,

given the following datastructure i want to create a resolv.conf file

dns:
    nameservers:
         '3': 10.200.1.230
         '4': 10.200.1.231
          .......
    search:
         cust0: a41mgt.local all-for-one.local
         cust1: A4T.local
         ......

for the nameserver list it is easy to itaerate over the list calling a defined type with a concat resource. 

the search list gives me  headache because i need to concatinate a string from it. 
              a41mgt.local all-for-one.local A4T.local ...

any ideas ? 

Thanks

Stephen Marlow

unread,
Jan 9, 2015, 11:00:37 AM1/9/15
to puppet...@googlegroups.com
 You could likely use iteration in the future parser or recursion to build up the string, but what sits in my mind as the path of least resistance is inline templating (c.f. https://docs.puppetlabs.com/references/latest/function.html#inlinetemplate).

I ran a quick test along these lines and it appeared to produce appropriate output:

  $search = {
    'cust0' => 'a41mgt.local all-for-one.local',
    'cust1' => 'A4T.local',
    'cust2' => 'a4y.remote',
  }

  notify { "ILT Search: ${search}": }

  $string = inline_template("<%= @search.values.join(' ') %>")

  notify { "ILT String: ${string}": }

  Notice: ILT Search: cust2a4y.remotecust1A4T.localcust0a41mgt.local all-for-one.local
  Notice: ILT String: a4y.remote A4T.local a41mgt.local all-for-one.local

This can definitely be improved upon, but it seems to do the trick.


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/2b2a3b34-1120-4d61-bfd6-caae6f6b0303%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephen Marlow

unread,
Jan 9, 2015, 11:08:22 AM1/9/15
to puppet...@googlegroups.com
Yknow, completely disregard the above answer :p

I was looking at stdlib and completely forgot about it before playing with inline templating.

values and join in stdlib (https://github.com/puppetlabs/puppetlabs-stdlib) do what is needed here. Much less code smell that way :p

Michael Wörz

unread,
Jan 10, 2015, 12:00:40 PM1/10/15
to puppet...@googlegroups.com
Thanks a lot. i will try this on monday

You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/HuptPetTEWw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CALGSqjLBP8zvEwmTYD2Q4_J0FPhsdzAPFuoBc1xHL0KgHrEc7A%40mail.gmail.com.

Michael Wörz

unread,
Jan 12, 2015, 10:12:52 AM1/12/15
to puppet...@googlegroups.com
I now mannaged to create the file accourately using the concat ressource. sort() also did the job. 
Reply all
Reply to author
Forward
0 new messages