在puppet中添加一个key =>值对的正确语法?

我正在puppetlabs-haproxy模块( https://github.com/puppetlabs/puppetlabs-haproxy ),并试图添加检测特定haproxy侦听器是否应启用统计信息侦听器的function。 这是我得到的:

 define haproxy::listen ( $ports, $ipaddress = $::ipaddress, $mode = 'tcp', $collect_exported = true, $stats_uri = false, $options = { 'option' => [ 'tcplog', ], 'balance' => 'roundrobin', } ) { if ($stats_uri) { $options['stats'] => 'uri /' #<=======SYNTAX ERROR HERE } # Template uses: $name, $ipaddress, $ports, $options concat::fragment { "${name}_listen_block": order => "20-${name}-1", target => '/etc/haproxy/haproxy.cfg', content => template('haproxy/haproxy_listen_block.erb'), } if $collect_exported { Haproxy::Balancermember <<| listening_service == $name |>> } # else: the resources have been created and they introduced their # concat fragments. We don't have to do anything about them. } 

主要区别是我已经添加了一个参数$stats_uri ,我试图testing是否设置,并添加一个键/值对$options如果是。

目前,我得到一个语法错误,因为你显然不这样做,就像我在做标记行。

所以问题是,如何根据是否设置$stats_uri来设置$options对象?

那么$options['stats'] = 'uri /'可能有效。 但不要这样做 – 取决于意外的行为不是一个好主意 。

相反,使不同的选项自己的参数:

 define haproxy::listen ( $ports, $ipaddress = $::ipaddress, $mode = 'tcp', $collect_exported = true, $stats_uri = false, $option = [ 'tcplog' ], $option_balance = 'roundrobin', $option_stats = undef, ) { if ($stats_uri) { $options_stats = 'uri /' }