Nested / Derived attributes

#1

Hi

I'm trying to build up a file path based on multiple attributes.

i.e. an attribute for a base folder then use another attribute for sub folder and reference in a recipe.

e.g.

default['application']['environment']['server_path'] = "E:\Apps\server"
default['application']['environment']['instance_name'] = "instance_1"
default['application']['environment']['license_path'] = "#{node['application']['environment']['server_path']}\license.lic"
default['application']['environment']['log_dir'] = "#{node['application']['environment']['server_path']}\#{node['application']['environment']['instance_name']}\LogFiles"

The first nested attribute works :
default['application']['environment']['license_path'] = "#{node['application']['environment']['server_path']}\license.lic"

but If i try to use attribute1\attribute2\folder for the ['application']['environment']['log_dir'] I always get syntax error.

= "#{node['application']['environment']['server_path']}\#{node['application']['environment']['instance_name']}\LogFiles"

(Annoyingly I'm sure I got it work once I'm sure but since broken.)

I'm hoping this is a simple Chef / Ruby syntax issue but failed to crack it so far today. Any Chef gurus who'll know this in a blink of an eye?

any help with this would be great! :slight_smile:

thanks

David

0 Likes

#2

What is the syntax error you are getting?

0 Likes

#3

I think you need to escape those backslashes in your double-quoted string:

irb(main):001:0> puts "something\something"
something omething
=> nil
irb(main):002:0> puts "something\\something"
something\something
=> nil

It is likely escaping the # in the second instance to make it a literal #. (Not sure what the exact syntax error would be though)

0 Likes