Skip to content

Instantly share code, notes, and snippets.

@rmoriz
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmoriz/c95118441dd93cfda3c3 to your computer and use it in GitHub Desktop.
Save rmoriz/c95118441dd93cfda3c3 to your computer and use it in GitHub Desktop.
data bag loading to node object
data_bag = node[cookbook_name]['encrypted_data_bag'] % { hostname: node['hostname'] }
data_bag_item = node[cookbook_name]['encrypted_data_bag_item'] % { hostname: node['hostname'] }
begin
secret = Chef::EncryptedDataBagItem.load_secret(Chef::Config['encrypted_data_bag_secret'])
encrypted_dbi = Chef::EncryptedDataBagItem.load(data_bag, data_bag_item, secret)
node.force_default[cookbook_name] = Chef::Mixin::DeepMerge.deep_merge(node[cookbook_name], encrypted_dbi.to_hash)
rescue => e
Chef::Log.error e
Chef::Log.error "could not load encrypted data bag item '#{data_bag}/#{data_bag_item}' - will use default attributes instead"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment