Skip to content

Instantly share code, notes, and snippets.

@dmerrick
Created September 24, 2014 23:46
Show Gist options
  • Select an option

  • Save dmerrick/f3e19870e5be7a4ee567 to your computer and use it in GitHub Desktop.

Select an option

Save dmerrick/f3e19870e5be7a4ee567 to your computer and use it in GitHub Desktop.
Use encrypted data bags without chef
#!/usr/bin/env ruby
# this is a proof-of-concept for reading encrypted data bags
# from a ruby script. you only need chef to be installed.
require 'rubygems'
require 'chef/rest'
require 'chef/encrypted_data_bag_item'
# prevent chef from trying to contact a server
Chef::Config[:solo] = true
# set up location of your data
Chef::Config[:data_bag_path] = './chef/data_bags'
Chef::Config[:encrypted_data_bag_secret] = './chef/data_bags/encrypted_data_bag_secret'
# just using newrelic as an example here
data = Chef::EncryptedDataBagItem.load('credentials', 'newrelic')
puts data['license_key']
# => "9c395..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment