Skip to content

Instantly share code, notes, and snippets.

@zzondlo
Forked from juanje/update_sources_list.rb
Created April 7, 2012 14:45
Show Gist options
  • Save zzondlo/2329462 to your computer and use it in GitHub Desktop.
Save zzondlo/2329462 to your computer and use it in GitHub Desktop.
Upada 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