I have a ERB(database.yml.erb) file template for database.yml for rendering using chef 11.10
I want to have an output(after rendering in chef) in database.yml, like below:
default: &default
adapter: mysql2
username: <%= ENV['diff_db_user'] || <username> %>
password: <%= ENV['diff_db_password'] || <password> %>
...
In the above yaml, I expect the values <username>
and <password>
are substituted from @node[:database][:username]
& @node[:database][:password]
So, the reason I wanted to do this is, to use a different password just by setting the environment variable while running a rake job like db migration
So, I tried the above with using escaping the erb tag as mentioned in How do I escape the ERB tag in ERB but in the output yml I could see the value is not substituted, it just prints the variable itself
for example I had an erb like this:
default: &default
adapter: mysql2
username: <%%= ENV['diff_db_user'] || @node[:database][:username] %>
password: <%%= ENV['diff_db_password'] || @node[:database][:password] %>
...
The output I'm getting for it is:
default: &default
adapter: mysql2
username: <%= ENV['diff_db_user'] || @node[:database][:username] %>
password: <%= ENV['diff_db_password'] || @node[:database][:password] %>
...
So, wanted to know is there any other way for to get printed like the one I initially mentioned at the top, when using template
in chef to render the erb to yml