Advertisement
Guest User

Untitled

a guest
Jun 13th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. Here is how to pass sensitive data to a template and yet make it easy to dynamically add non-sensitive attributes.
  2. Have non-sensitive attributes follow this pattern: `node[‘cookbook’][‘collection’][‘value_1’] = ‘value1’` where collection contains a collection of one or more attributes (one level deep). e.g.,
  3. ```ruby
  4. default['mycookbook']['conf']['db_driver'] = 'com.mysql.jdbc.Driver'
  5. default['mycookbook']['conf']['db_user'] = 'db_user'
  6. default['mycookbook']['conf']['db_pass'] = nil
  7. ```
  8.  
  9. Next step is create a separate hash, e.g.,
  10. ```ruby
  11. conf = {}.merge(node['mycookbook']['conf']) # a workaround for Chef dsl not supporting clone or deep copy
  12. ```
  13.  
  14. Then merge sensitive values the separate hash, e.g.,
  15. ```ruby
  16. conf.merge!(
  17. db_pass: mysql_data_bag[node['mycookbook']['conf']['db_user']],
  18. ...
  19. )
  20. ```
  21. Finally pass the separate hash to template:
  22. ```ruby
  23. template "#{app_path}/WEB-INF/application/conf/application.conf" do
  24. local true
  25. source "#{app_path}/WEB-INF/application/conf/application.conf.erb"
  26. variables conf
  27. mode ‘0600'
  28. owner user
  29. group group
  30. sensitive true
  31. action :create
  32. end
  33. ```
  34.  
  35. The erb file has the following values get overwritten:
  36.  
  37. ```
  38. db.url=<%= @db_url %>
  39. db.user=<%= @db_user %>
  40. db.pass=<%= @db_pass %>
  41. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement