Попытка установки значений по умолчанию в массиве хэшей в Puppet.
Я пытаюсь настроить URL для мониторинга.
Он должен содержать:
- url
- имя
- runbook
- комментарий [Необязательно]
- безопасный [по умолчанию = true]
- предупреждение [по умолчанию = 30]
- критический [ default = 15]
Я получил следующий код:
puppet apply test.pp
test.pp:
class http_monitoring (
Array[Struct[{
url => String,
name => String,
runbook => String,
Optional[comment] => String,
Optional[secure] => Boolean,
Optional[warning] => Integer,
Optional[critical] => Integer,
}]]
$checks = [{
secure => true,
warning => 30,
critical => 15,
}]
){
$checks.each | Hash $check | {
notify {"${check}":}
}
}
class website {
class { 'http_monitoring':
checks => [
{url => 'https://example.com', name => 'example' ,runbook => 'https://link-to-docs.com/'},
{url => 'https://example2.com', name => 'example2' ,runbook => 'https://link-to-docs.com/', warning => 5, critical => 10},
]
}
}
include website
Результаты:
Notice: {url => https://example.com, name => example, runbook => https://link-to-docs.com/}
Notice: /Stage[main]/Http_monitoring/Notify[{url => https://example.com, name => example, runbook => https://link-to-docs.com/}]/message: defined 'message' as '{url => https://example.com, name => example, runbook => https://link-to-docs.com/}'
Notice: {url => https://example2.com, name => example2, runbook => https://link-to-docs.com/, warning => 5, critical => 10}
Notice: /Stage[main]/Http_monitoring/Notify[{url => https://example2.com, name => example2, runbook => https://link-to-docs.com/, warning => 5, critical => 10}]/message: defined 'message' as '{url => https://example2.com, name => example2, runbook => https://link-to-docs.com/, warning => 5, critical => 10}'
Notice: Applied catalog in 0.01 seconds
Вывод, который я надеялся получить:
{url => 'https://example.com', name => example, runbook => https://link-to-docs.com/, secure => true, warning => 30, critical => 15}
{url => 'https://example2.com', name => 'example2', runbook => 'https://link-to-docs.com/', warning => 5, critical => 10, secure => true}
Запуск Puppet 6.12.0