Skip to content

Instantly share code, notes, and snippets.

@juanje
Created January 9, 2012 12:27
Show Gist options
  • Save juanje/1582734 to your computer and use it in GitHub Desktop.
Save juanje/1582734 to your computer and use it in GitHub Desktop.
Update sources_list data_bag
#!/usr/bin/env ruby
require 'debsfromrepos'
require 'chef/config'
require 'chef/data_bag'
Chef::Config.from_file('./.chef/knife.rb')
data_bag = 'sources_list'
rest = Chef::REST.new(Chef::Config[:chef_server_url])
data_bag_object = Chef::DataBag.load('sources_list')
data_bag_object.each_key do |item|
data_bag_item = Chef::DataBagItem.load(data_bag, item)
sources_list = data_bag_item.to_hash
server = sources_list['server']
sources_list["packages"].each_pair do |suite,components|
components.each_key do |component|
repo = DebsFromRepos::ListUrl.new(server,suite,component)
pkgs_url, translations_url = repo.get_packages_url, repo.get_translations_url('es')
pkgs = DebsFromRepos::Packages.new(pkgs_url, translations_url)
sources_list["packages"][suite][component] = pkgs.packages
end
end
item = Chef::DataBagItem.from_hash(sources_list)
item.data_bag(data_bag)
rest.post_rest("data/#{data_bag}", item)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment