- From: Lamont Granquist <
>
- To:
- Cc: Gordon Franke <
>
- Subject: [chef] Re: Resource attribute environment
- Date: Mon, 16 Feb 2015 10:02:57 -0800
On 2/16/15 2:17 AM, Gordon Franke wrote:
Hello,
i have found several variants of the environment attribute.
environment "PATH" => "/my/path/to/bin:#{ENV["PATH"]}"
environment ({'HOME' => '/home/myhome'})
environment { 'VAR' => 'whatever' }
What is the correct one and what is the difference?
Best Regards
Gordon
Fairly certain the last one is incorrect, and the ruby parser interprets
`environment { whatever }` to mean that you're passing a block rather
than a hash, and when it sees hashrockets (=>) in what it thinks is a
block it'll throw a syntax error at you. This is a limitation of the
ruby language because `{}` can be ambiguous and mean either a hash or a
block.
I think these forms all work:
environment "foo" => "bar", "fizz" => "buzz"
environment( "foo" => "bar", "fizz" => "buzz" )
environment( { "foo" => "bar", "fizz" => "buzz" } )
The choice between them comes down to style. I actually prefer the last
one in this specific case because its makes it the easiest to see that
it has to parse correctly, and is easiest on my aged braincells. I
think you'll be forced into that case if you want to pass the empty hash
as well, and I don't like rules with additional special cases:
environment # this is the accessor, does not set
environment() # this is the accessor, does not set
environment {} # passes a block
environment({}) # this correctly passes an empty hash
Archive powered by MHonArc 2.6.16.