ce88c3bd83814f575399972fa573463179ad1a77
[puppet-modules/puppetlabs-apt.git] / manifests / init.pp
1 # Class: apt
2 #
3 # This module manages the initial configuration of apt.
4 #
5 # Parameters:
6 #   The parameters listed here are not required in general and were
7 #     added for use cases related to development environments.
8 #   disable_keys - disables the requirement for all packages to be signed
9 #   always_apt_update - rather apt should be updated on every run (intended
10 #     for development environments where package updates are frequent
11 #   purge_sources_list - Accepts true or false. Defaults to false If set to
12 #     true, Puppet will purge all unmanaged entries from sources.list"
13 #   purge_sources_list_d - Accepts true or false. Defaults to false. If set
14 #     to false, Puppet will purge all unmanaged entries from sources.list.d
15 #
16 # Actions:
17 #
18 # Requires:
19 #
20 # Sample Usage:
21 #  class { 'apt': }
22 class apt(
23   $always_apt_update = false,
24   $disable_keys = undef,
25   $proxy_host = false,
26   $proxy_port = '8080',
27   $purge_sources_list = false,
28   $purge_sources_list_d = false
29 ) {
30
31   include apt::params
32   include apt::update
33
34   validate_bool($purge_sources_list, $purge_sources_list_d)
35
36   if ! defined(Package['python-software-properties']) {
37     package { 'python-software-properties': }
38   }
39
40   $sources_list_content = $purge_sources_list ? {
41     false => undef,
42     true  => "# Repos managed by puppet.\n",
43   }
44
45   if $always_apt_update == true {
46     Exec <| title=='apt update' |> {
47       refreshonly => false,
48     }
49   }
50
51   $root           = $apt::params::root
52   $apt_conf_d     = $apt::params::apt_conf_d
53   $sources_list_d = $apt::params::sources_list_d
54   $provider       = $apt::params::provider
55
56   file { 'sources.list':
57     ensure  => present,
58     path    => "${root}/sources.list",
59     owner   => root,
60     group   => root,
61     mode    => '0644',
62     content => $sources_list_content,
63     notify  => Exec['apt update'],
64   }
65
66   file { 'sources.list.d':
67     ensure  => directory,
68     path    => $sources_list_d,
69     owner   => root,
70     group   => root,
71     purge   => $purge_sources_list_d,
72     recurse => $purge_sources_list_d,
73     notify  => Exec['apt update'],
74   }
75
76   case $disable_keys {
77     true: {
78       file { '99unauth':
79         ensure  => present,
80         content => "APT::Get::AllowUnauthenticated 1;\n",
81         path    => "${apt_conf_d}/99unauth",
82       }
83     }
84     false: {
85       file { '99unauth':
86         ensure => absent,
87         path   => "${apt_conf_d}/99unauth",
88       }
89     }
90     undef:   { } # do nothing
91     default: { fail('Valid values for disable_keys are true or false') }
92   }
93
94   if ($proxy_host) {
95     file { 'configure-apt-proxy':
96       path    => "${apt_conf_d}/proxy",
97       content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";",
98       notify  => Exec['apt update'],
99     }
100   }
101 }