在puppet中调用split函数后如何修复“无法将String转换为Integer”?

时间:2011-12-05 07:59:15

标签: arrays debian puppet

如何修复以下代码?

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

请参阅:http://docs.puppetlabs.com/references/2.6.8/function.html#split

对我而言会导致以下错误:

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

尝试用以下方法修复它:

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

使用以下命令我现在得到错误,但也没有输出

notice( "${parts}" )

我有debian挤压运行其稳定的木偶包2.6.2-5 + squeeze3 puppetmaster也是debian稳定的2.6.2-5 + squeeze3

问题是“扯掉”一个“真正的”问题,我试图让duritong shorewall模块启动并运行(https://github.com/duritong/puppet-shorewall)

那里的shorewall ::条目失败并显示消息:

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

完整代码

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

2 个答案:

答案 0 :(得分:1)

看起来你正在遇到Puppet issue #5127,问题在于数组取消引用而不是分割函数。

修复是至少升级到puppet 2.6.3版。

答案 1 :(得分:0)

基本上,split("some-text", "-")相当于$_.split("some-text", "-")。结果取决于$_的值,其中包含gets读取的最后一个字符串。您可能想要做的是"some-text".split("-"),这会产生["some", "text"]