Quantcast
Channel: Ask Puppet: Puppet DevOps Q&A Community - RSS feed
Viewing all articles
Browse latest Browse all 6104

Build a new Array from an array

$
0
0
Hello I have an array. Its dynamic and i'll never know for definite how many elements there'll be in that array - all i know is that each element will be a set of characters separated by dashes. Here's one instance: [ab-wl-uat1, bc-wl-uat1, pc-wl-uat1, bg-too-uat2] I'm trying to recreate an array from that one inside a puppet manifest. All i want, though, is the set of characters after the last "-" from each element - so in this case i'd like to return: [uat1, uat1, uat1, uat2] I've tried so many things it's unreal! The nearest i get to something is this: $old = [ab-wl-uat1, bc-wl-uat1, pc-wl-uat1, bg-too-uat2] $newarray = split(inline_template("<%= @old.join(',') %>"),'-') But this just returns: [ab, wl, uat1,bc, wl, uat1,pc, wl, uat1,bg, too, uat2] And i've tried to dynamically build a new array through iteration - it was something like this, which just didn't work at all: $old.each |$x| { $namein=inline_template("<%= @x.split('-')[-1] %>") $namearray=any2array($namein) $newarray = concat($namearray, $newarray) notice($newarray) } newarray just ended up being one element long (I suspect because variables are immutable in puppet?) Can anyone give me any pointers as to what i'm doing wrong, at all please? i'm on puppet 2016.1 Cheers!

Viewing all articles
Browse latest Browse all 6104


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>