Re: Re: JSON Role files, attributes, and variable interpolation


#1

To further clarify:

Role data can be dynamic, as long as the dynamic part is pure Ruby, and
does not rely on any external data, such as node attributes.

Roles in Ruby will be converted to JSON data structures, so you may use
Ruby in a role before uploading it, but once uploaded, you will no longer
be able to download the precompiled Ruby form.

For instance:
Ruby:
default_attributes(
‘package_list’ => %w(foo bar)
)

JSON, from Chef Server:
“default_attributes”: {
“package_list”: [
“foo”,
“bar”
]
}

-M

On Tue Dec 30 2014 at 2:07:49 PM Noah Kantrowitz noah@coderanger.net
wrote:

No, nor would this work in the ruby format. Role data must be purely
static. You can do things like this in cookbooks though.

–Noah

On December 30, 2014 at 10:41:15 AM PST, Mark Selby <
mselby@thenextbigsound.com> wrote:

I use JSON based role files and for better or worse use them often for
attribute definition.

I have recently tried to perform variable interpolation like this

"default_attributes": {
    "foo": {
        "server": "extra.#{node['fqdn']}"
      }

I was not surprised that this DID NOT work and that I got
’extra.#{node[‘fqdn’]}’ rather than an interpolated string.

Is there any way to interpolate in JSON role files?

Thanks