Merge pull request #514 from psoloway/readme
[puppet-modules/puppetlabs-apt.git] / manifests / source.pp
index ea24cbfe442bda3b106571e8222e8f8ba920e872..40fc015bb6e8a194038d50e1f7444cb0bfc965b8 100644 (file)
@@ -1,26 +1,31 @@
 # source.pp
 # add an apt source
 define apt::source(
-  $comment           = $name,
-  $ensure            = present,
-  $location          = '',
-  $release           = $::lsbdistcodename,
-  $repos             = 'main',
-  $include_src       = false,
-  $include_deb       = true,
-  $key               = undef,
-  $pin               = false,
-  $architecture      = undef,
-  $trusted_source    = false,
+  $location       = undef,
+  $comment        = $name,
+  $ensure         = present,
+  $release        = $::apt::xfacts['lsbdistcodename'],
+  $repos          = 'main',
+  $include        = {},
+  $key            = undef,
+  $pin            = undef,
+  $architecture   = undef,
+  $allow_unsigned = false,
 ) {
-  validate_string($architecture, $comment, $location, $release, $repos)
-  validate_bool($trusted_source, $include_src, $include_deb)
+  validate_string($architecture, $comment, $location, $repos)
+  validate_bool($allow_unsigned)
+  validate_hash($include)
 
-  if ! $release {
+  unless $release {
     fail('lsbdistcodename fact not available: release parameter required')
   }
 
+  if $ensure == 'present' and ! $location {
+    fail('cannot create a source entry without specifying a location')
+  }
+
   $_before = Apt::Setting["list-${title}"]
+  $_include = merge($::apt::include_defaults, $include)
 
   if $key {
     if is_hash($key) {
@@ -30,6 +35,7 @@ define apt::source(
       $_key = merge($::apt::source_key_defaults, $key)
     } else {
       validate_string($key)
+      $_key = $key
     }
   }
 
@@ -38,17 +44,22 @@ define apt::source(
     content => template('apt/_header.erb', 'apt/source.list.erb'),
   }
 
-  if ($pin != false) {
-    # Get the host portion out of the url so we can pin to origin
-    $url_split = split($location, '/')
-    $host      = $url_split[2]
-
-    apt::pin { $name:
-      ensure   => $ensure,
-      priority => $pin,
-      before   => $_before,
-      origin   => $host,
+  if $pin {
+    if is_hash($pin) {
+      $_pin = merge($pin, { 'ensure' => $ensure, 'before' => $_before })
+    } elsif (is_numeric($pin) or is_string($pin)) {
+      $url_split = split($location, '/')
+      $host      = $url_split[2]
+      $_pin = {
+        'ensure'   => $ensure,
+        'priority' => $pin,
+        'before'   => $_before,
+        'origin'   => $host,
+      }
+    } else {
+      fail('Received invalid value for pin parameter')
     }
+    create_resources('apt::pin', { "${name}" => $_pin })
   }
 
   # We do not want to remove keys when the source is absent.
@@ -64,9 +75,9 @@ define apt::source(
         before  => $_before,
       }
     } else {
-      apt::key { "Add key: ${key} from Apt::Source ${title}":
+      apt::key { "Add key: ${_key} from Apt::Source ${title}":
         ensure => present,
-        id     => $key,
+        id     => $_key,
         before => $_before,
       }
     }