if ($variable) after upgrade from 5.5 to 6

26 views
Skip to first unread message

Helmut Schneider

unread,
Jun 17, 2020, 11:11:40 AM6/17/20
to puppet...@googlegroups.com
Hi,

helmut@puppet:~$ sudo puppet lookup --node mynode roles
helmut@puppet:~$

Good because does not exist.

class common inherits config {
include $classes
if ($roles) {
keys($roles).each |String $role| { <== line9
[...]

Error: Could not retrieve catalog from remote server: Error 500 on
SERVER: Server Error: Evaluation Error: Error while evaluating a
Function Call, 'keys' parameter 'hsh' expects a Hash value, got Array
(file: /etc/puppetlabs/code/modules/common/manifests/init.pp, line: 9,
column: 5) on node mynode

Why? $roles does not exists so why is keys($roles).each |String $role| {
executed?

helmut@puppet:~$ puppet -V
6.16.0
helmut@puppet:~$ puppetserver -v
puppetserver version: 6.12.0
helmut@puppet:~$

Thank you!

Helmut Schneider

unread,
Jun 17, 2020, 11:37:49 AM6/17/20
to puppet...@googlegroups.com
Am 17.06.2020 um 13:10 schrieb Helmut Schneider:

> helmut@puppet:~$ sudo puppet lookup --node mynode roles
> helmut@puppet:~$
>
> Good because does not exist.
>
> class common inherits config {
> include $classes
> if ($roles) {
> keys($roles).each |String $role| { <== line9
> [...]
>
> Error: Could not retrieve catalog from remote server: Error 500 on
> SERVER: Server Error: Evaluation Error: Error while evaluating a
> Function Call, 'keys' parameter 'hsh' expects a Hash value, got Array
> (file: /etc/puppetlabs/code/modules/common/manifests/init.pp, line: 9,
> column: 5) on node mynode
>
> Why? $roles does not exists so why is keys($roles).each |String $role| {
> executed?

I forgot:

$roles = lookup({
"name" => "roles",
"merge" => {
"strategy" => "deep",
"knockout_prefix" => "--",
# "sort_merged_arrays" => true,
},
# "default_value" => [],
"default_value" => undef,
})

I had "default_value" => [] active. Anyway, I thought that if
($variable) is an empty array it also results in 'false'. Can I check if
an array has elements?

Dirk Heinrichs

unread,
Jun 17, 2020, 1:01:46 PM6/17/20
to puppet...@googlegroups.com
Am Mittwoch, den 17.06.2020, 13:37 +0200 schrieb Helmut Schneider:

Can I check if  an array has elements?

if size($something) > 0 {}

HTH...

Dirk
-- 
Dirk Heinrichs
Senior Systems Engineer, Delivery Pipeline
OpenText ™ Discovery | Recommind
Recommind GmbH, Von-Liebig-Straße 1, 53359 Rheinbach
Vertretungsberechtigte Geschäftsführer Gordon Davies, Madhu Ranganathan, Christian Waida, Registergericht Amtsgericht Bonn, Registernummer HRB 10646
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind nicht gestattet.
signature.asc

Helmut Schneider

unread,
Jun 19, 2020, 9:29:43 AM6/19/20
to puppet...@googlegroups.com
Am 17.06.2020 um 15:01 schrieb 'Dirk Heinrichs' via Puppet Users:
> Am Mittwoch, den 17.06.2020, 13:37 +0200 schrieb Helmut Schneider:
>
>> Can I check if  an array has elements?
>
> if size($something) > 0 {}

Found $array.empty but thank you.

Reply all
Reply to author
Forward
0 new messages