Skip to content

Instantly share code, notes, and snippets.

@jcookfastrobot
Created September 19, 2018 06:15
Show Gist options
  • Save jcookfastrobot/51f8b940d842aea2cbe0f72a15163904 to your computer and use it in GitHub Desktop.
Save jcookfastrobot/51f8b940d842aea2cbe0f72a15163904 to your computer and use it in GitHub Desktop.
Module 12
#
# Cookbook:: apt_repos
# Recipe:: default
#
# Copyright:: 2017, The Authors, All Rights Reserved.
execute 'apt_refresh' do
command 'apt update'
action :nothing
end
repos = search('repos', '*:*')
repos.each do |repo|
if repo.key?('key')
execute 'apt_key_add' do
command "apt-key add #{Chef::Config['file_cache_path']}/#{repo['id']}.pub"
action :nothing
end
remote_file "#{Chef::Config['file_cache_path']}/#{repo['id']}.pub" do
source repo['key']
notifies :run, 'execute[apt_key_add]', :immediately
not_if "apt-key list | grep -i #{repo['id']}"
end
end
template "/etc/apt/sources.list.d/#{repo['id']}.list" do
source 'repo.erb'
owner 'root'
group 'root'
mode 0644
variables(
deb: repo['deb'],
enabled: repo['enabled']
)
notifies :run, 'execute[apt_refresh]'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment