Add encrypted databag options to chef-solo

This commit is contained in:
Christian Rigdon 2012-03-13 16:27:11 -06:00
parent 05756cbea5
commit b4e24c91f5
3 changed files with 20 additions and 1 deletions

View File

@ -15,6 +15,10 @@ module Vagrant
attr_accessor :data_bags_path attr_accessor :data_bags_path
attr_accessor :recipe_url attr_accessor :recipe_url
attr_accessor :nfs attr_accessor :nfs
attr_accessor :encrypted_data_bag_secret_key_path
attr_accessor :encrypted_data_bag_secret
def encrypted_data_bag_secret; @encrypted_data_bag_secret || "/tmp/encrypted_data_bag_secret"; end
def initialize def initialize
super super
@ -86,6 +90,7 @@ module Vagrant
verify_binary(chef_binary_path("chef-solo")) verify_binary(chef_binary_path("chef-solo"))
chown_provisioning_folder chown_provisioning_folder
upload_encrypted_data_bag_secret if config.encrypted_data_bag_secret_key_path
setup_json setup_json
setup_solo_config setup_solo_config
run_chef_solo run_chef_solo
@ -155,6 +160,12 @@ module Vagrant
end end
end end
def upload_encrypted_data_bag_secret
env[:ui].info I18n.t("vagrant.provisioners.chef.upload_encrypted_data_bag_secret_key")
env[:vm].channel.upload(encrypted_data_bag_secret_key_path,
config.encrypted_data_bag_secret)
end
def setup_solo_config def setup_solo_config
cookbooks_path = guest_paths(@cookbook_folders) cookbooks_path = guest_paths(@cookbook_folders)
roles_path = guest_paths(@role_folders).first roles_path = guest_paths(@role_folders).first
@ -167,6 +178,7 @@ module Vagrant
:recipe_url => config.recipe_url, :recipe_url => config.recipe_url,
:roles_path => roles_path, :roles_path => roles_path,
:data_bags_path => data_bags_path, :data_bags_path => data_bags_path,
:encrypted_data_bag_secret => config.encrypted_data_bag_secret,
}) })
end end
@ -207,6 +219,10 @@ module Vagrant
end end
end end
def encrypted_data_bag_secret_key_path
File.expand_path(config.encrypted_data_bag_secret_key_path, env[:root_path])
end
protected protected
# Extracts only the remote paths from a list of folders # Extracts only the remote paths from a list of folders

View File

@ -6,6 +6,8 @@ cookbook_path <%= cookbooks_path.inspect %>
role_path <%= roles_path.inspect %> role_path <%= roles_path.inspect %>
log_level <%= log_level.inspect %> log_level <%= log_level.inspect %>
encrypted_data_bag_secret "<%= encrypted_data_bag_secret %>"
<% if data_bags_path -%> <% if data_bags_path -%>
data_bag_path <%= data_bags_path.inspect %> data_bag_path <%= data_bags_path.inspect %>
<% end %> <% end %>

View File

@ -87,7 +87,8 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
:cookbooks_path => @action.guest_paths(@action.cookbook_folders), :cookbooks_path => @action.guest_paths(@action.cookbook_folders),
:recipe_url => @config.recipe_url, :recipe_url => @config.recipe_url,
:roles_path => @action.guest_paths(@action.role_folders).first, :roles_path => @action.guest_paths(@action.role_folders).first,
:data_bags_path => @action.guest_paths(@action.data_bags_folders).first :data_bags_path => @action.guest_paths(@action.data_bags_folders).first,
:encrypted_data_bag_secret => @config.encrypted_data_bag_secret
}) })
@action.setup_solo_config @action.setup_solo_config