Created
August 19, 2011 17:39
-
-
Save mpasternacki/1157440 to your computer and use it in GitHub Desktop.
Knife plugin to create data bags from YAML files
This file contains 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
# | |
# Author:: Maciej Pasternacki (<maciej@pasternacki.net>) | |
# Copyright:: Copyright (c) 2010 Maciej Pasternacki | |
# License:: Apache License, Version 2.0 | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# | |
require 'chef/knife' | |
class Chef | |
class Knife | |
class DataBagFromYaml < Knife | |
deps do | |
require 'chef/knife/data_bag_from_file' | |
Chef::Knife::DataBagFromFile.load_deps | |
require 'yaml' | |
require 'tempfile' | |
end | |
banner "knife data bag from yaml BAG FILE (options)" | |
category "data bag" | |
def run | |
databag_from_file = Chef::Knife::DataBagFromFile.new | |
data_bag, item_path = name_args[0], name_args[1] | |
data = YAML::load_file( | |
databag_from_file.loader.find_file("data_bags", data_bag, item_path)) | |
tmpf = Tempfile.new([data_bag, '.json']) | |
tmpf.puts Chef::JSONCompat.to_json(data) | |
tmpf.close | |
databag_from_file.config = config | |
databag_from_file.name_args = [ data_bag, tmpf.path ] | |
databag_from_file.run | |
end | |
end | |
end | |
end |
Not sure if you figured this out yet @developerinlondon but do you have this file in the correct spot?
yes this should be a Gem, or a Knife Plugin package rather than a file.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
also i get:
NoMethodError: undefined method
deps' for #<Class:0x007fb3f41d23d8>::Chef::Knife::DataBagFromYaml ~/chef-nolio/.chef/knife.rb:18:in
class:DataBagFromYaml'~/chef-nolio/.chef/knife.rb:17:in
<class:Knife>' ~f/chef-nolio/.chef/knife.rb:16:in
class:Chef'~/chef-nolio/.chef/knife.rb:15:in `from_string'
Relevant file content:
17: class DataBagFromYaml < Knife
18: deps do
19: require 'chef/knife/data_bag_from_file'