puppet 3.x selectors with hashes - syntax error

229 views
Skip to first unread message

Maxim Ianoglo

unread,
Mar 28, 2013, 8:48:20 AM3/28/13
to puppet...@googlegroups.com
Hello,

I am facing a issue that is not present in Puppet version 2.X.
At construction like:
$panel_tcp_in = $control_panel ? {
    cpanel      => {'admin_interface' => '2087', 'user_interface' => '2077,2078,2082,2083,2086,2095,2096'},                                                                                                                          
    directadmin => {'admin_interface' => '2222', 'user_interface' => '2222'},
    plesk       => {'admin_interface' => '8443', 'user_interface' => '8443'},                                                                                                                                                         
    default     => {'admin_interface' => '', 'user_interface' => ''}
}

I am getting:
    err: Could not retrieve catalog from remote server: Error 400 on SERVER: Syntax error at '{'; expected '}' at .... on node ....

Did anyone face such issue before ? may be there is custom patch or something that could fix this ...

OS: CentOS 6 64 bit
Ruby: ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux]
Puppet: 3.1.1

Thank you.
--
Maxim Ianoglo

jcbollinger

unread,
Mar 29, 2013, 9:24:43 AM3/29/13
to puppet...@googlegroups.com

It looks like a bug to me, but there's a pretty easy workaround: pull out the selector body as a hash of hashes, and select the desired value via ordinary hash indexing.  The only trick is handling the 'default' case, but that's doable:

$panel_options = {
    cpanel      => {'admin_interface' => '2087', 'user_interface' => '2077,2078,2082,2083,2086,2095,2096'},
    directadmin => {'admin_interface' => '2222', 'user_interface' => '2222'},
    plesk       => {'admin_interface' => '8443', 'user_interface' => '8443'}
}

if has_key($panel_options, $control_panel) {
    $panel_tcp_in = $panel_options[$control_panel]
} else {
    $panel_tcp_in = {'admin_interface' => '', 'user_interface' => ''}
}


Note that the 'has_key' function is not built-in; instead, it comes from Puppetlabs' "stdlib" add-in module.  You can achieve the same thing without, but it's longer and uglier.


John

Reply all
Reply to author
Forward
0 new messages