Skip to content

Instantly share code, notes, and snippets.

@matschaffer
Created June 8, 2012 15:30
Show Gist options
  • Select an option

  • Save matschaffer/2896172 to your computer and use it in GitHub Desktop.

Select an option

Save matschaffer/2896172 to your computer and use it in GitHub Desktop.

Revisions

  1. matschaffer created this gist Jun 8, 2012.
    11 changes: 11 additions & 0 deletions create_data_bag.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    require 'rubygems'
    require 'chef/encrypted_data_bag_item'

    secret = Chef::EncryptedDataBagItem.load_secret('data_bag_key')
    data = {"id" => "mysql", "root" => "some secret password"}
    encrypted_data = Chef::EncryptedDataBagItem.encrypt_data_bag_item(data, secret)

    FileUtils.mkpath('data_bags/passwords')
    File.open('data_bags/passwords/mysql.json', 'w') do |f|
    f.print encrypted_data.to_json
    end