Issue #16268 has been updated by Jochen Schalanda.

Eric, thanks for picking up the issue.

The Puppet 2.7 Reference Manual says in the [paragraph on 
selectors](http://docs.puppetlabs.com/puppet/2.7/reference/lang_conditional.html#values):

<blockquote>
Values may be any of the following:
<ul>
<li><b>A literal value</b></li>
<li>A variable</li>
<li>A function call that returns a value</li>
<li>Another selector</li>
</blockquote>

Coming from a programming background I assumed that arrays (`['a', 'b', 'c']`) 
and hashes (`{ 'a' => 1, 'b' => 2 }`) are also treatead as literal values - 
which they are when assigning them to a variable.
----------------------------------------
Bug #16268: Hash literals not allowed inside conditional block
https://projects.puppetlabs.com/issues/16268#change-71036

Author: Jochen Schalanda
Status: Needs More Information
Priority: Normal
Assignee: Jochen Schalanda
Category: language
Target version: 
Affected Puppet version: 
Keywords: dsl
Branch: 


The Puppet DSL currently doesn’t allow hash literals expressions being used as 
the value in a conditional block. Using a temporary variable which holds the 
value works, though.

Non-working example:

    $test = undef ? {
      undef   => { 'test' => 'success' },
      default => 'foo',
    }
    notice($test)
    
Result with Puppet 2.7.19:

    $ puppet apply conditional_hash.pp 
    Could not parse for environment production: Syntax error at '{'; expected 
'}' at /tmp/conditional_hash.pp:2 on node localhost

Working example:

    $my_hash = { 'test' => 'success' }
    $test = undef ? {
      undef   => $my_hash,
      default => 'foo',
    }
    notice($test)

Result:

    $ puppet apply conditional_hash2.pp 
    notice: Scope(Class[main]): {"test"=>"success"}
    notice: Finished catalog run in 0.03 seconds


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to