Array becomes string in template

30 views
Skip to first unread message

Frederik Himpe

unread,
Apr 24, 2014, 6:18:16 AM4/24/14
to puppet...@googlegroups.com
I'm experiencing this error on a template:

Failed to parse template mailman/mm_cfg.py.erb:#012 Filepath: /etc/puppet/modules/mailman/templates/mm_cfg.py.erb#012 Line: 103#012 Detail: undefined method `each' for "example1.com\", \"example2.com\", \"example3.com":String#012

The line in question in the template looks like this:

POSTFIX_STYLE_VIRTUAL_DOMAINS = [<% @virtualhost.join('", "').each do |v| %>"<%= @v %>"<% end -%>]

The class mailman contains like this:

class mailman ( $defaulthost,
$virtualhost = [],
$postfix = false) {

file { "/etc/mailman/mm_cfg.py":
owner => "root", group => "root", mode => "0644",
content => template("mailman/mm_cfg.py.erb"),
require => [ Package["mailman"], Class["mta"] ],
}
}

And it's called like this:

class {"mailman":
defaulthost => "example1.com",
virtualhost => ["example1.com", "example2.com", "example3.com"],
postfix => true,
}

So why has this virtualhost array suddenly become a string
when I call the each function on it in the template?

This all worked fine with an older version of puppet master (not sure
which version exactly), but it's broken now with more recent
versions (puppet master 3.5.1, the agent is still running 2.7.23
however).

What could be wrong here?

--
Frederik Himpe

Matthias Saou

unread,
Apr 24, 2014, 7:11:55 AM4/24/14
to puppet...@googlegroups.com
On Thu, 24 Apr 2014 10:18:16 +0000 (UTC)
Frederik Himpe <fhi...@vub.ac.be> wrote:

> The line in question in the template looks like this:
>
> POSTFIX_STYLE_VIRTUAL_DOMAINS = [<% @virtualhost.join('", "').each do
> |v| %>"<%= @v %>"<% end -%>]
>
[...]
> So why has this virtualhost array suddenly become a string
> when I call the each function on it in the template?

Because unless I'm mistaken, you're converting your array to a string
with ".join('", "')". Just remove that, and the ".each" should be
correctly applied to the array.

Matthias

--
Matthias Saou ██ ██
██ ██
Web: http://matthias.saou.eu/ ██████████████
Mail/XMPP: matt...@saou.eu ████ ██████ ████
██████████████████████
GPG: 4096R/E755CC63 ██ ██████████████ ██
8D91 7E2E F048 9C9C 46AF ██ ██ ██ ██
21A9 7A51 7B82 E755 CC63 ████ ████

Frederik Himpe

unread,
Apr 24, 2014, 7:38:00 AM4/24/14
to puppet...@googlegroups.com
On Thu, 24 Apr 2014 13:11:55 +0200, Matthias Saou wrote:

> On Thu, 24 Apr 2014 10:18:16 +0000 (UTC)
> Frederik Himpe <fhi...@vub.ac.be> wrote:
>
>> The line in question in the template looks like this:
>>
>> POSTFIX_STYLE_VIRTUAL_DOMAINS = [<% @virtualhost.join('", "').each do
>> |v| %>"<%= @v %>"<% end -%>]
>>
> [...]
>> So why has this virtualhost array suddenly become a string
>> when I call the each function on it in the template?
>
> Because unless I'm mistaken, you're converting your array to a string
> with ".join('", "')". Just remove that, and the ".each" should be
> correctly applied to the array.

Of course! Thanks, that does the trick.

--
Frederik Himpe

Reply all
Reply to author
Forward
0 new messages