我正在破解模块puppetlabs-haproxy
(https://github.com/puppetlabs/puppetlabs-haproxy),我正在尝试添加检测特定 haproxy 侦听器是否应启用统计侦听器的功能。这是我得到的:
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
,并且尝试测试该参数是否已设置,$options
如果已设置,则添加一个键/值对。
目前,我遇到了语法错误,因为您显然没有像我在标记的行中那样执行此操作。
所以问题是,我如何$options
根据是否$stats_uri
设置来操作对象?
答案1
嗯,$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 /'
}