Created
March 12, 2012 21:41
-
-
Save scottsbaldwin/2024855 to your computer and use it in GitHub Desktop.
knife plugin to set data bag attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This knife plugin provides the capability to set an attribute | |
| # value in a data bag item. By default the 'versions' data bag | |
| # is used, but that can be overridden with the -b option. | |
| # Copy this file to ~/.chef/plugins/knife to install the plugin. | |
| module KnifePlugins | |
| class DataBagVersionSet < Chef::Knife | |
| deps do | |
| require 'chef/data_bag' | |
| end | |
| banner "knife data bag version set ITEM ATTRIBUTE VALUE" | |
| category 'data bag' | |
| option :bag, :short => '-b', :long => '--bag', :description => 'The name of the versions data bag, default is: versions' | |
| def run | |
| if @name_args.length < 3 | |
| show_usage | |
| ui.fatal("Please specify all arguments") | |
| exit 1 | |
| end | |
| @data_bag_item, @attribute, @value = @name_args | |
| if config[:bag] | |
| @data_bag_name = config[:bag] | |
| else | |
| @data_bag_name = 'versions' | |
| end | |
| if @data_bag_name.nil? | |
| @data_bag_name = 'versions' | |
| end | |
| bag_item = Chef::DataBagItem.load(@data_bag_name, @data_bag_item) | |
| bag_item[@attribute] = @value | |
| bag_item.save | |
| puts "#{@data_bag_name}/#{@data_bag_item}/#{@attribute} saved." | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment