(#12522) Adding purge option to apt class
[puppet-modules/puppetlabs-apt.git] / manifests / init.pp
index 677523bcf267c0fb8a9d7725f877e8a313a3f1aa..b0acdd0927f60de80bd6abfc0236fa4bea37ae32 100644 (file)
@@ -1,29 +1,75 @@
-# apt.pp
+# Class: apt
+#
+# This module manages the initial configuration of apt.
+#
+# Parameters:
+#   Both of the parameters listed here are not required in general and were
+#     added for use cases related to development environments.
+#   disable_keys - disables the requirement for all packages to be signed
+#   always_apt_update - rather apt should be updated on every run (intended
+#     for development environments where package updates are frequent
+# Actions:
+#
+# Requires:
+#
+# Sample Usage:
+#  class { 'apt': }
+class apt(
+  $always_apt_update = false,
+  $disable_keys = false,
+  $proxy_host = false,
+  $proxy_port = '8080',
+  $purge = false
+) {
 
-class apt {
-       $root = '/etc/apt'
-       $provider = '/usr/bin/apt-get'
+  include apt::params
+
+  validate_bool($purge)
+
+  $refresh_only_apt_update = $always_apt_update? {
+    true => false,
+    false => true
+  }
 
   package { "python-software-properties": }
 
-       file { "sources.list":
-               name => "${root}/sources.list",
-               ensure => present,
-               owner => root,
-               group => root,
-               mode => 644,
-       }
-
-       file { "sources.list.d":
-               name => "${root}/sources.list.d",
-               ensure => directory,
-               owner => root,
-               group => root,
-       }
-
-       exec { "apt_update":
-               command => "${provider} update",
-               subscribe => [ File["sources.list"], File["sources.list.d"] ],
-               refreshonly => true,
-       }
+  file { "sources.list":
+    path => "${apt::params::root}/sources.list",
+    ensure => present,
+    owner => root,
+    group => root,
+    mode => 644,
+    content => $purge ? {
+      false =>  undef,
+      true  => "# Repos managed by puppet.\n",
+    },
+  }
+
+  file { "sources.list.d":
+    path => "${apt::params::root}/sources.list.d",
+    ensure => directory,
+    owner => root,
+    group => root,
+    purge => $purge,
+    recurse => $purge,
+  }
+
+  exec { "apt_update":
+    command => "${apt::params::provider} update",
+    subscribe => [ File["sources.list"], File["sources.list.d"] ],
+    refreshonly => $refresh_only_apt_update,
+  }
+  if($disable_keys) {
+    exec { 'make-apt-insecure':
+      command => '/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth',
+      creates => '/etc/apt/apt.conf.d/99unauth'
+    }
+  }
+
+  if($proxy_host) {
+    file { 'configure-apt-proxy':
+      path    => '/etc/apt/apt.conf.d/proxy',
+      content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";",
+    }
+  }
 }