Update apt cookbook

This commit is contained in:
Greg Karékinian
2018-04-17 13:43:22 +02:00
parent 6a86fc64fa
commit b92cc6e5d7
21 changed files with 833 additions and 441 deletions

View File

@@ -1,8 +1,8 @@
#
# Cookbook Name:: apt
# Cookbook:: apt
# Recipe:: cacher-client
#
# Copyright 2011-2013 Chef Software, Inc.
# Copyright:: 2011-2017, Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -17,10 +17,6 @@
# limitations under the License.
#
class ::Chef::Recipe
include ::Apt
end
# remove Acquire::http::Proxy lines from /etc/apt/apt.conf since we use 01proxy
# these are leftover from preseed installs
execute 'Remove proxy from /etc/apt/apt.conf' do
@@ -28,56 +24,29 @@ execute 'Remove proxy from /etc/apt/apt.conf' do
only_if 'grep Acquire::http::Proxy /etc/apt/apt.conf'
end
servers = []
if node['apt']
if node['apt']['cacher_ipaddress']
cacher = Chef::Node.new
cacher.default.name = node['apt']['cacher_ipaddress']
cacher.default.ipaddress = node['apt']['cacher_ipaddress']
cacher.default.apt.cacher_port = node['apt']['cacher_port']
cacher.default.apt.cacher_interface = node['apt']['cacher_interface']
cacher.default.apt.cacher_ssl_support = node['apt']['cacher_ssl_support']
servers << cacher
elsif node['apt']['caching_server']
node.override['apt']['compiletime'] = false
servers << node
if node['apt']['cacher_client']['cacher_server'].empty?
Chef::Log.warn("No cache server defined in node['apt']['cacher_client']['cacher_server']. Not setting up caching")
f = file '/etc/apt/apt.conf.d/01proxy' do
action(node['apt']['compiletime'] ? :nothing : :delete)
end
end
unless Chef::Config[:solo] || servers.length > 0
query = 'apt_caching_server:true'
query += " AND chef_environment:#{node.chef_environment}" if node['apt']['cacher-client']['restrict_environment']
Chef::Log.debug("apt::cacher-client searching for '#{query}'")
servers += search(:node, query)
end
if servers.length > 0
Chef::Log.info("apt-cacher-ng server found on #{servers[0]}.")
if servers[0]['apt']['cacher_interface']
cacher_ipaddress = interface_ipaddress(servers[0], servers[0]['apt']['cacher_interface'])
else
cacher_ipaddress = servers[0].ipaddress
f.run_action(:delete) if node['apt']['compiletime']
else
apt_update 'update for notification' do
action :nothing
end
t = template '/etc/apt/apt.conf.d/01proxy' do
source '01proxy.erb'
owner 'root'
group 'root'
mode 00644
mode '0644'
variables(
proxy: cacher_ipaddress,
port: servers[0]['apt']['cacher_port'],
proxy_ssl: servers[0]['apt']['cacher_ssl_support'],
bypass: node['apt']['cache_bypass']
server: node['apt']['cacher_client']['cacher_server']
)
action(node['apt']['compiletime'] ? :nothing : :create)
notifies :run, 'execute[apt-get update]', :immediately
notifies :update, 'apt_update[update for notification]', :immediately
end
t.run_action(:create) if node['apt']['compiletime']
else
Chef::Log.info('No apt-cacher-ng server found.')
file '/etc/apt/apt.conf.d/01proxy' do
action :delete
end
end
include_recipe 'apt::default'