Bug #5860

arrays do not work in selectors

Added by Adam Crews over 1 year ago. Updated 12 days ago.

Status:Accepted Start date:01/12/2011
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:-
Target version:2.7.x
Affected Puppet version: Branch:
Keywords:
Votes: 3

Description

Using an array in a selector does not work:

$info = [ "acrews", "Adam", "/bin/bash" ] 
$shell = $info[2] ? { 
    /bin/ => $info[2], 
    default => "/sbin/nologin", 
} 

I get: Syntax error at ‘?’; expected ‘}

If I do this it works:

$info = [ "acrews", "Adam", "/bin/bash" ] 
$AA = $info[2] 
$shell => $AA ? { 
   /bin/ => $info[2], 
   default => "/sbin/nologin", 
}

An array element should be able to be used exactly like any normal variable.

I see this on 2.6.4.


Related issues

related to Puppet - Bug #5516: Hashes can't be used in selectors Closed 12/12/2010

History

Updated by Nigel Kersten over 1 year ago

  • Status changed from Unreviewed to Accepted
  • Target version set to 2.7.x

Updated by Peter Meier about 1 year ago

Also the following does not work:

$foo = []
$real_foo = $foo ? {
  [] => [ 960010 ],
  default => $foo
}

notice $real_foo

Updated by Adam Crews 8 months ago

The original code reported in this ticket now works on pe-1.2.1. The code in the comments still doesn’t work.

Updated by Dominic Cleal 12 days ago

The same goes for returning hashes from a selector:

$foo = "test"
$real_foo = $foo ? {
  default => { test => "foo" },
}
notice($foo[test])

throws this:

err: Could not parse for environment production: Syntax error at '{'; expected '}' at /home/dcleal/tmp/5860.pp:3 ...

Also available in: Atom PDF