Duplicate definition : Merging arrays

2,149 views
Skip to first unread message

iamauser

unread,
Aug 22, 2012, 9:56:58 AM8/22/12
to puppet...@googlegroups.com
Hello,

I am trying to create a new array by combining two other arrays. I get the following error while running :

Duplicate definition: Print[test0] is already defined in file /etc/puppet/manifests/test.pp at line 47; cannot redefine at /etc/puppet/manifests/test.pp:47

My code is similar to this :
<snip>
.....
.....
$sys_server =       [ ginger , test0 ]
$usr_server  =  [ test0, test1, test2 ]

$server = split(inline_template("<%= (sys_server+usr_server).join(',') %>"),',')
.....
.....
</snip>

This way clearly not working. Is there a tweak somewhere to remove the duplicates while joining the arrays ? or is there any other way to join two arrays to create another one ?

Thanks very much.

Nan Liu

unread,
Aug 22, 2012, 12:52:10 PM8/22/12
to puppet...@googlegroups.com
Use the unique and join function from stdlib.

Nan

iamauser

unread,
Aug 22, 2012, 1:29:27 PM8/22/12
to puppet...@googlegroups.com
Any example, for this case ? I didn't find any on the web...

thanks

Nan Liu

unread,
Aug 22, 2012, 1:42:16 PM8/22/12
to puppet...@googlegroups.com
On Wed, Aug 22, 2012 at 10:29 AM, iamauser <tapas....@gmail.com> wrote:
> Any example, for this case ? I didn't find any on the web...
>
> thanks

Bleh, join is string only. unique will remove any duplicates:

$sys_server = [ ginger , test0 ]
$usr_server = [ test0, test1, test2 ]

$all = [$sys_server, $usr_server]

$server = unique(flatten($all))

notify { $server: }

Nan

Nick Fagerlund

unread,
Aug 22, 2012, 1:43:11 PM8/22/12
to puppet...@googlegroups.com
You can see inline docs for every stdlib function by reading the code:

https://github.com/puppetlabs/puppetlabs-stdlib/tree/master/lib/puppet/parser/functions

Install the module with:

$ sudo puppet module install puppetlabs-stdlib

And probably use unique and flatten to do what you're trying to do. Like this.

$server = unique( flatten( [$sys_server, $usr_server] ) )

Nick Fagerlund

unread,
Aug 22, 2012, 1:44:25 PM8/22/12
to puppet...@googlegroups.com
Whoops, collision! Reassuring that we both did the same thing though. :)
Reply all
Reply to author
Forward
Message has been deleted
0 new messages