Helmut Schneider
unread,Jul 11, 2018, 11:32:24 AM7/11/18Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to puppet...@googlegroups.com
Hello all,
let's assume the following structure in a yaml:
profiles:
vpn:
openvpn:
instances:
client:
myclient:
remote: 'openvpn_host 1194'
I would now like to check if e.g. "client" exists:
if ($profiles['vpn']['openvpn']['instances']['client'])
This works as long as the structure
profiles:
vpn:
openvpn:
instances:
exists and fails if not (because OpenVPN should not be available for
that client):
Error: Could not retrieve catalog from remote server: Error 500 on
SERVER: Server Error: Evaluation Error: Operator '[]' is not applicable
to an Undef Value. at
/etc/puppetlabs/code/modules/openvpn/manifests/init.pp:17:7 on node
my_client
Is there a way to check the existence of a hierarchy without creating
an empty hierarchy or doing something like
if is_hash($profiles) {
if has_key($profiles, 'vpn') {
if has_key($profiles['vpn'], 'openvpn') {
if has_key($profiles['vpn']['openvpn'], 'instances') {
...and so on
}
}
}
}
Thank you!