X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=manifests%2Fsource.pp;h=be743eb26ca207fc9a3c2b09f82a52caff3ae494;hb=d7af638793b6f5b6c5af6562923fa9ee0b025e1d;hp=958bf25c79fea2e9b250a2dd09554da911a8e645;hpb=494abedaebb87be7208581e28142f68a3f3404a2;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/manifests/source.pp b/manifests/source.pp index 958bf25..be743eb 100644 --- a/manifests/source.pp +++ b/manifests/source.pp @@ -1,31 +1,39 @@ # source.pp # add an apt source define apt::source( - $location = undef, - $comment = $name, - $ensure = present, - $release = $::apt::xfacts['lsbdistcodename'], - $repos = 'main', - $include = {}, - $key = undef, - $pin = undef, - $architecture = undef, - $allow_unsigned = false, + Optional[String] $location = undef, + String $comment = $name, + String $ensure = present, + Optional[String] $release = undef, + String $repos = 'main', + Optional[Variant[Hash]] $include = {}, + Optional[Variant[String, Hash]] $key = undef, + $pin = undef, + Optional[String] $architecture = undef, + Boolean $allow_unsigned = false, + Boolean $notify_update = true, ) { - validate_string($architecture, $comment, $location, $repos) - validate_bool($allow_unsigned) - validate_hash($include) - unless $release { - fail('lsbdistcodename fact not available: release parameter required') + # This is needed for compat with 1.8.x + include ::apt + + $_before = Apt::Setting["list-${title}"] + + if !$release { + if $facts['lsbdistcodename'] { + $_release = $facts['lsbdistcodename'] + } else { + fail('lsbdistcodename fact not available: release parameter required') + } + } else { + $_release = $release } 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) + $includes = merge($::apt::include_defaults, $include) if $key { if is_hash($key) { @@ -34,22 +42,35 @@ define apt::source( } $_key = merge($::apt::source_key_defaults, $key) } else { - validate_string($key) - $_key = $key + validate_legacy(String, 'validate_string', $key) + $_key = { 'id' => $key } } } + $header = epp('apt/_header.epp') + + $sourcelist = epp('apt/source.list.epp', { + 'comment' => $comment, + 'includes' => $includes, + 'opt_architecture' => $architecture, + 'allow_unsigned' => $allow_unsigned, + 'location' => $location, + 'release' => $_release, + 'repos' => $repos, + }) + apt::setting { "list-${name}": - ensure => $ensure, - content => template('apt/_header.erb', 'apt/source.list.erb'), + ensure => $ensure, + content => "${header}${sourcelist}", + notify_update => $notify_update, } 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] + $url_split = split($location, '[:\/]+') + $host = $url_split[1] $_pin = { 'ensure' => $ensure, 'priority' => $pin, @@ -74,12 +95,6 @@ define apt::source( options => $_key['options'], before => $_before, } - } else { - apt::key { "Add key: ${_key} from Apt::Source ${title}": - ensure => present, - id => $_key, - before => $_before, - } } } }