2015-01-09 22:17:51 +01:00
|
|
|
# == Class: apt
|
2011-05-30 03:43:01 +02:00
|
|
|
#
|
|
|
|
# This module manages the initial configuration of apt.
|
|
|
|
#
|
2015-01-09 22:17:51 +01:00
|
|
|
# The parameters listed here are not required in general and were
|
|
|
|
# added for use cases related to development environments.
|
2014-08-18 22:12:55 +02:00
|
|
|
#
|
2015-01-09 22:17:51 +01:00
|
|
|
# === Parameters
|
2014-08-18 22:12:55 +02:00
|
|
|
#
|
2015-01-09 22:17:51 +01:00
|
|
|
# [*disable_keys*]
|
|
|
|
# Disables the requirement for all packages to be signed
|
2014-08-18 22:12:55 +02:00
|
|
|
#
|
2015-01-09 22:17:51 +01:00
|
|
|
# [*always_apt_update*]
|
|
|
|
# Rather apt should be updated on every run (intended
|
|
|
|
# for development environments where package updates are frequent)
|
|
|
|
#
|
|
|
|
# [*apt_update_frequency*]
|
|
|
|
# String: Supported values:
|
|
|
|
# **always**: Will fire `apt-get update` at every puppet run. Intended to
|
2014-08-18 22:12:55 +02:00
|
|
|
# deprecate the `always_apt_update` parameter.
|
2015-01-09 22:17:51 +01:00
|
|
|
# *daily**: Trigger `apt-get update` if the value of the fact
|
2014-08-18 22:12:55 +02:00
|
|
|
# `apt_update_last_success` is less than current epoch time - 86400.
|
|
|
|
# *notifying the apt_update exec will trigger apt-get update regardless*
|
2015-01-09 22:17:51 +01:00
|
|
|
# *weekly**: Trigger `apt-get update` if the value of the fact
|
2014-08-18 22:12:55 +02:00
|
|
|
# `apt_update_last_success` is less than current epoch time - 604800.
|
|
|
|
# *notifying the apt_update exec will trigger apt-get update regardless*
|
2015-01-09 22:17:51 +01:00
|
|
|
# *reluctantly**: *Default* only run apt-get update if the exec resource `apt_update` is notified.
|
|
|
|
#
|
|
|
|
# [*purge_sources_list*]
|
|
|
|
# Accepts true or false. Defaults to false If set to
|
|
|
|
# true, Puppet will purge all unmanaged entries from sources.list
|
|
|
|
#
|
|
|
|
# [*purge_sources_list_d*]
|
|
|
|
# Accepts true or false. Defaults to false. If set
|
|
|
|
# to true, Puppet will purge all unmanaged entries from sources.list.d
|
|
|
|
#
|
|
|
|
# [*update_timeout*]
|
|
|
|
# Overrides the exec timeout in seconds for apt-get update.
|
|
|
|
# If not set defaults to Exec's default (300)
|
2014-08-18 22:12:55 +02:00
|
|
|
#
|
2015-01-09 22:17:51 +01:00
|
|
|
# [*update_tries*]
|
|
|
|
# Number of times that `apt-get update` will be tried. Use this
|
|
|
|
# to work around transient DNS and HTTP errors. By default, the command
|
|
|
|
# will only be run once.
|
2014-08-18 22:12:55 +02:00
|
|
|
#
|
2015-01-09 22:17:51 +01:00
|
|
|
# === Examples
|
2014-08-18 22:12:55 +02:00
|
|
|
#
|
2015-01-09 22:17:51 +01:00
|
|
|
# class { 'apt': }
|
2014-08-18 22:12:55 +02:00
|
|
|
#
|
2015-01-09 22:17:51 +01:00
|
|
|
# === Requires
|
2012-02-24 18:27:28 +01:00
|
|
|
#
|
2015-01-09 22:17:51 +01:00
|
|
|
# puppetlabs/stdlib >= 2.2.1
|
2011-05-30 03:43:01 +02:00
|
|
|
#
|
|
|
|
class apt(
|
2012-05-22 00:48:00 +02:00
|
|
|
$always_apt_update = false,
|
2014-08-18 22:12:55 +02:00
|
|
|
$apt_update_frequency = 'reluctantly',
|
2012-05-22 00:48:00 +02:00
|
|
|
$disable_keys = undef,
|
2014-01-30 00:33:45 +01:00
|
|
|
$proxy_host = undef,
|
2012-05-22 00:48:00 +02:00
|
|
|
$proxy_port = '8080',
|
|
|
|
$purge_sources_list = false,
|
2012-05-22 00:51:33 +02:00
|
|
|
$purge_sources_list_d = false,
|
2014-02-22 10:56:50 +01:00
|
|
|
$purge_preferences = false,
|
2013-10-02 14:24:30 +02:00
|
|
|
$purge_preferences_d = false,
|
2013-12-04 19:05:26 +01:00
|
|
|
$update_timeout = undef,
|
2014-03-05 22:59:21 +01:00
|
|
|
$update_tries = undef,
|
2014-04-24 09:52:12 +02:00
|
|
|
$sources = undef,
|
|
|
|
$fancy_progress = undef
|
2011-05-30 03:43:01 +02:00
|
|
|
) {
|
2010-04-27 22:38:28 +02:00
|
|
|
|
2014-03-07 16:03:44 +01:00
|
|
|
if $::osfamily != 'Debian' {
|
|
|
|
fail('This module only works on Debian or derivatives like Ubuntu')
|
|
|
|
}
|
|
|
|
|
2014-08-18 22:12:55 +02:00
|
|
|
$frequency_options = ['always','daily','weekly','reluctantly']
|
|
|
|
validate_re($apt_update_frequency, $frequency_options)
|
2011-05-30 19:18:13 +02:00
|
|
|
include apt::params
|
2012-05-04 22:35:13 +02:00
|
|
|
include apt::update
|
2011-05-30 19:18:13 +02:00
|
|
|
|
2014-02-22 10:56:50 +01:00
|
|
|
validate_bool($purge_sources_list, $purge_sources_list_d,
|
|
|
|
$purge_preferences, $purge_preferences_d)
|
2012-02-08 20:40:09 +01:00
|
|
|
|
2012-03-21 14:35:48 +01:00
|
|
|
$sources_list_content = $purge_sources_list ? {
|
2012-05-03 18:51:14 +02:00
|
|
|
false => undef,
|
2012-03-21 14:35:48 +01:00
|
|
|
true => "# Repos managed by puppet.\n",
|
|
|
|
}
|
2012-04-11 23:54:13 +02:00
|
|
|
|
2012-05-04 22:35:13 +02:00
|
|
|
if $always_apt_update == true {
|
2012-05-04 00:44:17 +02:00
|
|
|
Exec <| title=='apt_update' |> {
|
2012-05-04 22:35:13 +02:00
|
|
|
refreshonly => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-18 22:12:55 +02:00
|
|
|
file { '/etc/apt/apt.conf.d/15update-stamp':
|
|
|
|
ensure => 'file',
|
2014-08-31 15:46:57 +02:00
|
|
|
content => template('apt/_header.erb', 'apt/15update-stamp.erb'),
|
2014-08-18 22:12:55 +02:00
|
|
|
group => 'root',
|
|
|
|
mode => '0644',
|
|
|
|
owner => 'root',
|
|
|
|
}
|
|
|
|
|
2012-04-11 23:54:13 +02:00
|
|
|
$root = $apt::params::root
|
|
|
|
$apt_conf_d = $apt::params::apt_conf_d
|
|
|
|
$sources_list_d = $apt::params::sources_list_d
|
2012-05-22 00:56:29 +02:00
|
|
|
$preferences_d = $apt::params::preferences_d
|
2012-04-11 23:54:13 +02:00
|
|
|
$provider = $apt::params::provider
|
|
|
|
|
2012-03-21 14:20:13 +01:00
|
|
|
file { 'sources.list':
|
|
|
|
ensure => present,
|
2012-04-11 23:54:13 +02:00
|
|
|
path => "${root}/sources.list",
|
2012-03-21 14:20:13 +01:00
|
|
|
owner => root,
|
|
|
|
group => root,
|
|
|
|
mode => '0644',
|
2012-03-21 14:35:48 +01:00
|
|
|
content => $sources_list_content,
|
2012-05-04 00:44:17 +02:00
|
|
|
notify => Exec['apt_update'],
|
2011-05-30 19:24:06 +02:00
|
|
|
}
|
2011-03-11 18:02:50 +01:00
|
|
|
|
2012-03-21 14:20:13 +01:00
|
|
|
file { 'sources.list.d':
|
|
|
|
ensure => directory,
|
2012-04-12 02:49:30 +02:00
|
|
|
path => $sources_list_d,
|
2012-03-21 14:20:13 +01:00
|
|
|
owner => root,
|
|
|
|
group => root,
|
|
|
|
purge => $purge_sources_list_d,
|
2012-02-24 18:27:28 +01:00
|
|
|
recurse => $purge_sources_list_d,
|
2012-05-04 00:44:17 +02:00
|
|
|
notify => Exec['apt_update'],
|
2011-05-30 03:43:01 +02:00
|
|
|
}
|
2012-02-10 01:18:14 +01:00
|
|
|
|
2014-05-05 12:06:39 +02:00
|
|
|
if $purge_preferences {
|
2014-05-02 23:35:54 +02:00
|
|
|
file { 'apt-preferences':
|
2014-09-05 18:51:39 +02:00
|
|
|
ensure => absent,
|
|
|
|
path => "${root}/preferences",
|
2014-05-02 23:35:54 +02:00
|
|
|
}
|
2014-02-22 10:56:50 +01:00
|
|
|
}
|
|
|
|
|
2012-05-22 00:51:33 +02:00
|
|
|
file { 'preferences.d':
|
|
|
|
ensure => directory,
|
|
|
|
path => $preferences_d,
|
|
|
|
owner => root,
|
|
|
|
group => root,
|
|
|
|
purge => $purge_preferences_d,
|
|
|
|
recurse => $purge_preferences_d,
|
|
|
|
}
|
|
|
|
|
2014-04-24 09:52:12 +02:00
|
|
|
case $fancy_progress {
|
|
|
|
true: {
|
|
|
|
file { '99progressbar':
|
|
|
|
ensure => present,
|
2014-08-31 15:46:57 +02:00
|
|
|
content => template('apt/_header.erb', 'apt/progressbar.erb'),
|
2014-04-24 09:52:12 +02:00
|
|
|
path => "${apt_conf_d}/99progressbar",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
false: {
|
|
|
|
file { '99progressbar':
|
2014-09-05 18:51:39 +02:00
|
|
|
ensure => absent,
|
|
|
|
path => "${apt_conf_d}/99progressbar",
|
2014-04-24 09:52:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
undef: {} # do nothing
|
|
|
|
default: { fail('Valid values for fancy_progress are true or false') }
|
|
|
|
}
|
|
|
|
|
2012-02-10 01:18:14 +01:00
|
|
|
case $disable_keys {
|
|
|
|
true: {
|
2012-03-21 14:20:13 +01:00
|
|
|
file { '99unauth':
|
2012-02-10 01:18:14 +01:00
|
|
|
ensure => present,
|
2014-08-31 15:46:57 +02:00
|
|
|
content => template('apt/_header.erb', 'apt/unauth.erb'),
|
2012-04-11 23:54:13 +02:00
|
|
|
path => "${apt_conf_d}/99unauth",
|
2012-02-10 01:18:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
false: {
|
2012-03-21 14:20:13 +01:00
|
|
|
file { '99unauth':
|
2012-02-10 01:18:14 +01:00
|
|
|
ensure => absent,
|
2012-04-11 23:54:13 +02:00
|
|
|
path => "${apt_conf_d}/99unauth",
|
2012-02-10 01:18:14 +01:00
|
|
|
}
|
2011-05-30 03:43:01 +02:00
|
|
|
}
|
2012-05-04 22:35:13 +02:00
|
|
|
undef: { } # do nothing
|
2012-03-21 14:20:13 +01:00
|
|
|
default: { fail('Valid values for disable_keys are true or false') }
|
2011-05-30 03:43:01 +02:00
|
|
|
}
|
2012-02-08 18:40:43 +01:00
|
|
|
|
2014-07-11 01:38:45 +02:00
|
|
|
case $proxy_host {
|
|
|
|
false, '', undef: {
|
|
|
|
file { '01proxy':
|
2014-09-05 18:51:39 +02:00
|
|
|
ensure => absent,
|
|
|
|
path => "${apt_conf_d}/01proxy",
|
|
|
|
notify => Exec['apt_update'],
|
2014-07-11 01:38:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
file { '01proxy':
|
|
|
|
ensure => present,
|
|
|
|
path => "${apt_conf_d}/01proxy",
|
2014-08-31 15:46:57 +02:00
|
|
|
content => template('apt/_header.erb', 'apt/proxy.erb'),
|
2014-07-11 01:38:45 +02:00
|
|
|
notify => Exec['apt_update'],
|
2014-07-11 23:33:15 +02:00
|
|
|
mode => '0644',
|
|
|
|
owner => root,
|
|
|
|
group => root,
|
2014-07-11 01:38:45 +02:00
|
|
|
}
|
|
|
|
}
|
2012-02-08 18:40:43 +01:00
|
|
|
}
|
2014-05-20 22:24:28 +02:00
|
|
|
|
2014-04-11 08:35:25 +02:00
|
|
|
file { 'old-proxy-file':
|
2014-09-05 18:51:39 +02:00
|
|
|
ensure => absent,
|
|
|
|
path => "${apt_conf_d}/proxy",
|
|
|
|
notify => Exec['apt_update'],
|
2014-04-11 08:35:25 +02:00
|
|
|
}
|
2012-05-08 00:27:53 +02:00
|
|
|
|
|
|
|
# Need anchor to provide containment for dependencies.
|
2012-08-21 22:55:24 +02:00
|
|
|
anchor { 'apt::update':
|
2012-05-08 00:27:53 +02:00
|
|
|
require => Class['apt::update'],
|
|
|
|
}
|
2013-12-04 19:05:26 +01:00
|
|
|
|
|
|
|
# manage sources if present
|
|
|
|
if $sources != undef {
|
2014-03-27 17:40:36 +01:00
|
|
|
validate_hash($sources)
|
|
|
|
create_resources('apt::source', $sources)
|
2013-12-04 19:05:26 +01:00
|
|
|
}
|
2010-04-27 22:38:28 +02:00
|
|
|
}
|