Hi David,
I think the problem lies with the Ruby syntax you're using, not the online docs.
As you pasted, from the docs:
This will evaluate the not_if
, decide that the resource should run, and then execute the command in the code
section, passing in the environment
hash as variables to this exact command.
Your example:
So a few of things spring to mind:
- The trailing brace that is triggering the error is the one right behind
gb'
in the code line.
- I don't think using the
<
operator directly to a code string works
- Trying to interpolate a string with single quotes will provide the exact string, not the value passed. Use double quotes for string interpolation:
[1] pry(main)> heap_size = 8
=> 8
[2] pry(main)> '#{heap_size}gb'
=> "\#{heap_size}gb"
[3] pry(main)> "#{heap_size}gb"
=> "8gb"
[4] pry(main)>
However, all this brings me to ask this:
It appears you are trying to set the environment variable for Elasticsearch heap size upon startup. If you're using a service
block to do this, then you likely want to set the variable before the service startup?
Using a bash resource typically invokes a subprocess, passes along any environment
settings and then exits, so those settings are not persisted for any other processes.
If so, there's a couple of ways to go about resolving.
- Add the value to your ES init script. See an example here.
- Set the environment variable before the service startup. See docs example here
Note that using option 2, the variable will only be present when starting the service via Chef - if you restart the service on command line, the environment variable will not be present.
There's a large variety of ways of setting environment variables in general, these are not the only ways to do it.
My preference is to have the value in the init script, then it's not in the environment, and can be inspected as a file later.
Hope this helps!
-M