Check if python-software-properties is defined before attempting to define it.
[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 = undef,
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   if ! defined(Package["python-software-properties"]) {
35     package { "python-software-properties": }
36   }
37
38   file { "sources.list":
39     path => "${apt::params::root}/sources.list",
40     ensure => present,
41     owner => root,
42     group => root,
43     mode => 644,
44     content => $purge ? {
45       false =>  undef,
46       true  => "# Repos managed by puppet.\n",
47     },
48   }
49
50   file { "sources.list.d":
51     path => "${apt::params::root}/sources.list.d",
52     ensure => directory,
53     owner => root,
54     group => root,
55     purge => $purge,
56     recurse => $purge,
57   }
58
59   exec { "apt_update":
60     command => "${apt::params::provider} update",
61     subscribe => [ File["sources.list"], File["sources.list.d"] ],
62     refreshonly => $refresh_only_apt_update,
63   }
64
65   case $disable_keys {
66     true: {
67       file { "99unauth":
68         content => "APT::Get::AllowUnauthenticated 1;\n",
69         ensure  => present,
70         path    => "/etc/apt/apt.conf.d/99unauth",
71       }
72     }
73     false: {
74       file { "99unauth":
75         ensure => absent,
76         path   => "/etc/apt/apt.conf.d/99unauth",
77       }
78     }
79     undef: { } # do nothing
80     default: { fail("Valid values for disable_keys are true or false") }
81   }
82
83   if($proxy_host) {
84     file { 'configure-apt-proxy':
85       path    => '/etc/apt/apt.conf.d/proxy',
86       content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";",
87     }
88   }
89 }