b0acdd0927f60de80bd6abfc0236fa4bea37ae32
[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 #   Both of 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 # Actions:
12 #
13 # Requires:
14 #
15 # Sample Usage:
16 #  class { 'apt': }
17 class apt(
18   $always_apt_update = false,
19   $disable_keys = false,
20   $proxy_host = false,
21   $proxy_port = '8080',
22   $purge = false
23 ) {
24
25   include apt::params
26
27   validate_bool($purge)
28
29   $refresh_only_apt_update = $always_apt_update? {
30     true => false,
31     false => true
32   }
33
34   package { "python-software-properties": }
35
36   file { "sources.list":
37     path => "${apt::params::root}/sources.list",
38     ensure => present,
39     owner => root,
40     group => root,
41     mode => 644,
42     content => $purge ? {
43       false =>  undef,
44       true  => "# Repos managed by puppet.\n",
45     },
46   }
47
48   file { "sources.list.d":
49     path => "${apt::params::root}/sources.list.d",
50     ensure => directory,
51     owner => root,
52     group => root,
53     purge => $purge,
54     recurse => $purge,
55   }
56
57   exec { "apt_update":
58     command => "${apt::params::provider} update",
59     subscribe => [ File["sources.list"], File["sources.list.d"] ],
60     refreshonly => $refresh_only_apt_update,
61   }
62   if($disable_keys) {
63     exec { 'make-apt-insecure':
64       command => '/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth',
65       creates => '/etc/apt/apt.conf.d/99unauth'
66     }
67   }
68
69   if($proxy_host) {
70     file { 'configure-apt-proxy':
71       path    => '/etc/apt/apt.conf.d/proxy',
72       content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";",
73     }
74   }
75 }