1

I am trying to figure out a way to get the below code work; I have tried various methods but the chef-client run breaks at the 3rd line.

lsf = "#{node[:env]}"+"_ls"
dsf = "#{node[:env]}"+"_ds"

dsTemplateBag = data_bag_item('configTemplates', "#{dsf}") 
lcTemplateBag = data_bag_item('configTemplates', "#{lsf}")

However on another test recipe I was able to successfully get the following working:

env = "test"

dsTemplateBag = data_bag_item('configTemplates', "#{env}")

I am quite new to Chef and please can someone advise me on how to get this working ?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user2986175
  • 337
  • 1
  • 3
  • 8
  • As your third line is blanck, hard to tell. you should not mix concatenation and interpolation, use `lsf = "#{node[:env]}_ls"` and whan you don't need to include a var in a string, just call it directly: `data_bag_item('configTemplates', lsf)` – Tensibai Feb 13 '15 at 11:00
  • Thank you for that suggestion. I actually tried that out initially and mixed concatenation and interpolation just to see if that would make it work. However in the end it turned out that the issue was with the data bag. I had a small typo in the data bag which was causing the issue. – user2986175 Feb 13 '15 at 17:48

1 Answers1

1

After a little bit debugging I realised there was a typo preventing the data bag to be properly used; hence issue.

dsTemplateBag = data_bag_item('configTemplates', "#{node[:env]}_ls")

this worked for me. And as Tensibai suggested in the above comment mixing concatenation and interpolation is not a good practice (I was desperate to make it work! In my defense).

user2986175
  • 337
  • 1
  • 3
  • 8