lib/capistrano/chef.rb in capistrano-chef-0.0.4 vs lib/capistrano/chef.rb in capistrano-chef-0.0.5

- old
+ new

@@ -21,11 +21,11 @@ arg when Hash iface, family = arg.keys.first.to_s, arg.values.first.to_s Proc.new do |n| addresses = n["network"]["interfaces"][iface]["addresses"] - addresses.select{|address, data| data["family"] == family }.keys.first + addresses.select{|address, data| data["family"] == family }.to_a.first.first end when Symbol, String Proc.new{|n| n[arg.to_s]} else raise ArgumentError, 'Search arguments must be Proc, Hash, Symbol, String.' @@ -35,21 +35,33 @@ def self.get_data_bag_item(id, data_bag = :apps) Chef::DataBagItem.load(data_bag, id).raw_data end + def self.get_encrypted_data_bag_item(id, data_bag = :apps, secret = nil) + Chef::EncryptedDataBagItem.load(data_bag, id, secret).to_hash + end + # Load into Capistrano def self.load_into(configuration) self.configure_chef configuration.set :capistrano_chef, self configuration.load do def chef_role(name, query = '*:*', options = {}) + options = {:attribute => :ipaddress, :limit => 1000}.merge(options) role name, *(capistrano_chef.search_chef_nodes(query, options.delete(:attribute), options.delete(:limit)) + [options]) end def set_from_data_bag(data_bag = :apps) raise ':application must be set' if fetch(:application).nil? capistrano_chef.get_data_bag_item(application, data_bag).each do |k, v| + set k, v + end + end + + def set_from_encrypted_data_bag(data_bag = :apps, secret = nil) + raise ':application must be set' if fetch(:application).nil? + capistrano_chef.get_encrypted_data_bag_item(application, data_bag, secret).each do |k, v| set k, v end end end end