0

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]}",
    }
}
4

2 に答える 2

1

Puppet issue #5127が発生しているようで、問題は split 関数ではなく配列の逆参照にあるようです。

修正は、少なくとも puppet バージョン 2.6.3 にアップグレードすることです。

于 2011-12-14T00:57:39.703 に答える
0

基本的にsplit("some-text", "-")は と同等$_.split("some-text", "-")です。結果は、$_gets によって読み取られた最後の文字列を含む の値によって異なります。おそらくやりたいことは"some-text".split("-")であり、結果は になり["some", "text"]ます。

于 2011-12-05T08:35:47.043 に答える