c33s
c33s

Reputation: 2642

how to fix "can't convert String into Integer" after calling the split function in puppet?

how to fix the following code?

$parts = split('test-test','-')
notice( $parts[0] )

see: http://docs.puppetlabs.com/references/2.6.8/function.html#split

for me it results in the following error:

can't convert String into Integer at ....:2

tried to fix it with:

notice( ${parts[0]} )
notice( "${parts[0]}" )

with the following command i got now error, but also no output

notice( "${parts}" )

i have debian squeeze running with its stable puppet package 2.6.2-5+squeeze3 puppetmaster is also debian stable 2.6.2-5+squeeze3

the question is "ripped out" of a "real" problem, i am try to get the duritong shorewall module up and running (https://github.com/duritong/puppet-shorewall)

there the shorewall::entry fails with the message:

err: Could not retrieve catalog from remote server: Error 400 on SERVER: 
can't convert String into Integer at 
/etc/puppet/modules/shorewall/manifests/entry.pp:9 on node

full code

define shorewall::entry(
    $ensure = present,
    $line
){
    $parts = split($name,'-')

    concat::fragment{$name:
        ensure => $ensure,
        content => "${line}\n",
        order => $parts[1],
        target => "/etc/shorewall/puppet/${parts[0]}",
    }
}

Upvotes: 0

Views: 3243

Answers (2)

pwan
pwan

Reputation: 2914

It looks like you're running into Puppet issue #5127, and that the problem is with array dereference instead of the split function.

The fix is to upgrade to at least puppet version 2.6.3.

Upvotes: 1

moritz
moritz

Reputation: 25757

Basically, split("some-text", "-") is equivalent to $_.split("some-text", "-"). The result depends on the value of $_, which contains the last string read by gets. What you probably want to do is "some-text".split("-"), which results in ["some", "text"].

Upvotes: 0

Related Questions