Ask Your Question
0

unwanted flattening of array

asked 2013-03-27 15:58:38 -0500

redmine gravatar image

updated 2013-03-28 09:43:15 -0500

llowder gravatar image

I am trying to pass an array of ip addresses in a defined type. Like this : $ip_arr = ["1.2.3.4", "11.2.3.4", "88.22.33.55"]

When I print this variable in defined type, I get this ip_arr= 1.2.3.411.2.3.488.22.33.55 as an output.

I want it this way: ip_arr = "1.2.3.4 11.2.3.4 88.22.33.55".

Is it possible to make is work, without using stdlib?

edit retag flag offensive close merge delete

Comments

i am using puppet.-3.0.1

redmine gravatar imageredmine ( 2013-03-27 16:28:19 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-03-27 16:36:33 -0500

jonn gravatar image

updated 2013-03-27 17:16:27 -0500

Could you use the join() function from stdlib?

define test($iparray) {
        $ips = join($iparray, " ")
        notify { "The IPs are: $ips": }
}
$iparr = ["1.2.3.4","11.2.3.4","88.22.33.55"]

test { "Test:": iparray => $iparr }

This should print:

$ puppet apply tt.pp
notice: The IPs are: 1.2.3.4 11.2.3.4 88.22.33.55
notice: /Stage[main]//Test[Test:]/Notify[The IPs are: 1.2.3.4 11.2.3.4 88.22.33.55]/message: defined 'message' as 'The IPs are: 1.2.3.4 11.2.3.4 88.22.33.55'
notice ...
(more)
edit flag offensive delete link more

Comments

I am working in puppet DSL. and when i try your method by "puppet apply ". Puppet gives this error " unknown function join "

redmine gravatar imageredmine ( 2013-03-27 16:42:21 -0500 )edit

You may need to install the stdlib module - it's well worth it, there's lots of useful stuff in there. https://puppetlabs.com/blog/module-of-the-week-puppetlabsstdlib-puppet-labs-standard-library/ has a walkthrough which shows how.

jonn gravatar imagejonn ( 2013-03-27 16:47:06 -0500 )edit

Is there any oterh way . I mean is it possible to use ruby inline template here. I am new to ruby and puppet so dont know if its poissbile .

redmine gravatar imageredmine ( 2013-03-27 16:53:36 -0500 )edit

You can, yep - I've updated my answer with an example.

jonn gravatar imagejonn ( 2013-03-27 17:17:03 -0500 )edit

Also, I would prefer not to use standard library

redmine gravatar imageredmine ( 2013-03-27 17:17:24 -0500 )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

Stats

Asked: 2013-03-27 15:58:38 -0500

Seen: 792 times

Last updated: Mar 28 '13