From b87e1af3704f5574bda393e36ded542ee7c4be23 Mon Sep 17 00:00:00 2001 From: Helen Campbell Date: Tue, 20 Dec 2016 11:34:00 +0000 Subject: [PATCH] Puppet 4 language update --- CHANGELOG.md | 16 ++ data/Debian-6.0.yaml | 5 + data/Debian.yaml | 4 + data/Ubuntu-10.04.yaml | 4 + data/Ubuntu-12.04.yaml | 4 + data/Ubuntu-14.04.yaml | 4 + data/Ubuntu.yaml | 4 + data/common.yaml | 11 ++ hiera.yaml | 22 +++ manifests/backports.pp | 22 +-- manifests/conf.pp | 11 +- manifests/init.pp | 77 ++++++---- manifests/key.pp | 34 ++--- manifests/params.pp | 142 ------------------ manifests/pin.pp | 52 ++++--- manifests/ppa.pp | 17 +-- manifests/setting.pp | 25 +-- manifests/source.pp | 90 ++++++----- metadata.json | 7 +- spec/classes/apt_backports_spec.rb | 14 +- spec/classes/apt_spec.rb | 15 +- spec/classes/params_spec.rb | 22 --- spec/defines/key_compat_spec.rb | 6 +- spec/defines/key_spec.rb | 6 +- spec/defines/pin_spec.rb | 7 +- spec/defines/ppa_spec.rb | 9 ++ spec/defines/setting_spec.rb | 18 ++- spec/defines/source_spec.rb | 7 +- ...{15update-stamp.erb => 15update-stamp.epp} | 0 .../{_conf_header.erb => _conf_header.epp} | 0 templates/{_header.erb => _header.epp} | 0 templates/conf.erb | 1 - templates/pin.pref.epp | 26 ++++ templates/pin.pref.erb | 21 --- templates/proxy.epp | 5 + templates/proxy.erb | 4 - templates/source.list.epp | 10 ++ templates/source.list.erb | 9 -- 38 files changed, 356 insertions(+), 375 deletions(-) create mode 100644 data/Debian-6.0.yaml create mode 100644 data/Debian.yaml create mode 100644 data/Ubuntu-10.04.yaml create mode 100644 data/Ubuntu-12.04.yaml create mode 100644 data/Ubuntu-14.04.yaml create mode 100644 data/Ubuntu.yaml create mode 100644 data/common.yaml create mode 100644 hiera.yaml delete mode 100644 manifests/params.pp delete mode 100644 spec/classes/params_spec.rb rename templates/{15update-stamp.erb => 15update-stamp.epp} (100%) rename templates/{_conf_header.erb => _conf_header.epp} (100%) rename templates/{_header.erb => _header.epp} (100%) delete mode 100644 templates/conf.erb create mode 100644 templates/pin.pref.epp delete mode 100644 templates/pin.pref.erb create mode 100644 templates/proxy.epp delete mode 100644 templates/proxy.erb create mode 100644 templates/source.list.epp delete mode 100644 templates/source.list.erb diff --git a/CHANGELOG.md b/CHANGELOG.md index 25fbd7b..86d474a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ +## Supported Release 3.0.0 and 4.0.0 +###Summary + +This release adds new Puppet 4 features: data in modules, EPP templates, the $facts hash, and data types. This release is fully backwards compatible to existing Puppet 4 configurations and provides you with deprecation warnings for every argument that will not work as expected with the final 4.0.0 release. See the stdlib docs here for an in-depth discussion of this: https://github.com/puppetlabs/puppetlabs-stdlib#validate_legacy + +If you want to learn more about the new features used or you wish to upgrade a module yourself, have a look at the NTP: A Puppet 4 language update blog post. + +If you're still running Puppet 3, remain on the latest puppetlabs-apt 2.x release for now, and see the documentation to upgrade to Puppet 4. + +Changes + +Data in modules: Moves all distribution and OS-dependent defaults into YAML files in data/, alleviating the need for a params class. Note that while this feature is currently still classed as experimental, the final implementation will support the changes here. +EPP templating: Uses the Puppet language as a base for templates to create simpler and safer templates. No need for Ruby anymore! +The $facts hash: Makes facts visibly distinct from other variables for more readable and maintainable code. This helps eliminate confusion if you use a local variable whose name happens to match that of a common fact. +Data types for validation: Helps you find and replace deprecated code in existing validate functions with stricter, more readable data type notation. First upgrade to the 3.0.0 release of this module, and address all deprecation warnings before upgrading to the final 4.0.0 release. Please see the stdlib docs for an in-depth discussion of this process. + ## Supported Release 2.4.0 ### Summary A release that includes only a couple of additional features, but includes several cleanups and bugfixes around existing issues. diff --git a/data/Debian-6.0.yaml b/data/Debian-6.0.yaml new file mode 100644 index 0000000..f03bccd --- /dev/null +++ b/data/Debian-6.0.yaml @@ -0,0 +1,5 @@ +--- +#Squeeze +apt::backports: { location: 'http://httpredir.debian.org/debian-backports', key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', repos: 'main contrib non-free' } +apt::ppa_options: ~ +apt::ppa_package: ~ diff --git a/data/Debian.yaml b/data/Debian.yaml new file mode 100644 index 0000000..823bc02 --- /dev/null +++ b/data/Debian.yaml @@ -0,0 +1,4 @@ +--- +apt::backports: { location: 'http://httpredir.debian.org/debian', key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', repos: 'main contrib non-free' } +apt::ppa_options: ~ +apt::ppa_package: ~ diff --git a/data/Ubuntu-10.04.yaml b/data/Ubuntu-10.04.yaml new file mode 100644 index 0000000..567548b --- /dev/null +++ b/data/Ubuntu-10.04.yaml @@ -0,0 +1,4 @@ +--- +#Lucid +apt::ppa_options: ~ +apt::ppa_package: 'python-software-properties' diff --git a/data/Ubuntu-12.04.yaml b/data/Ubuntu-12.04.yaml new file mode 100644 index 0000000..992cb25 --- /dev/null +++ b/data/Ubuntu-12.04.yaml @@ -0,0 +1,4 @@ +--- +#Precise +apt::ppa_options: '-y' +apt::ppa_package: 'python-software-properties' diff --git a/data/Ubuntu-14.04.yaml b/data/Ubuntu-14.04.yaml new file mode 100644 index 0000000..d168164 --- /dev/null +++ b/data/Ubuntu-14.04.yaml @@ -0,0 +1,4 @@ +--- +#Trusty +apt::ppa_options: '-y' +apt::ppa_package: 'software-properties-common' diff --git a/data/Ubuntu.yaml b/data/Ubuntu.yaml new file mode 100644 index 0000000..ee62a25 --- /dev/null +++ b/data/Ubuntu.yaml @@ -0,0 +1,4 @@ +--- +apt::backports: { location: 'http://archive.ubuntu.com/ubuntu', key: '630239CC130E1A7FD81A27B140976EAF437D05B5', repos: 'main universe multiverse restricted' } +apt::ppa_options: '-y' +apt::ppa_package: 'python-software-properties' diff --git a/data/common.yaml b/data/common.yaml new file mode 100644 index 0000000..2ed9e16 --- /dev/null +++ b/data/common.yaml @@ -0,0 +1,11 @@ +--- +apt::provider: '/usr/bin/apt-get' +apt::keyserver: 'keyserver.ubuntu.com' +apt::update_defaults: { frequency: 'reluctantly', timeout: ~, tries: ~ } +apt::proxy_defaults: { ensure: ~, host: ~, port: 8080, https: false } +apt::purge_defaults: { sources.list: false, sources.list.d: false, preferences: false, preferences.d: false } +apt::proxy_defaults: { ensure: ~, host: ~, port: 8080, https: false } +apt::include_defaults: { deb: true, src: false } +apt::ppa_options: ~ +apt::ppa_package: ~ +apt::backports: ~ diff --git a/hiera.yaml b/hiera.yaml new file mode 100644 index 0000000..4bfe502 --- /dev/null +++ b/hiera.yaml @@ -0,0 +1,22 @@ +--- +version: 4 +datadir: data +hierarchy: + - name: "Full Version" + backend: yaml + path: "%{facts.os.name}-%{facts.os.release.full}" + + - name: "Major Version" + backend: yaml + path: "%{facts.os.name}-%{facts.os.release.major}" + + - name: "Distribution Name" + backend: yaml + path: "%{facts.os.name}" + + - name: "Operating System Family" + backend: yaml + path: "%{facts.os.family}" + + - name: "common" + backend: yaml diff --git a/manifests/backports.pp b/manifests/backports.pp index f7e85f5..06165b6 100644 --- a/manifests/backports.pp +++ b/manifests/backports.pp @@ -1,34 +1,34 @@ class apt::backports ( - $location = undef, - $release = undef, - $repos = undef, - $key = undef, - $pin = 200, + Optional[Variant[String, Stdlib::Compat::String]] $location = undef, + Optional[Variant[String, Stdlib::Compat::String]] $release = undef, + Optional[Variant[String, Stdlib::Compat::String]] $repos = undef, + Optional[Variant[String, Stdlib::Compat::String, Hash, Stdlib::Compat::Hash]] $key = undef, + Optional[Variant[Integer, Stdlib::Compat::Integer, String, Stdlib::Compat::String, Hash, Stdlib::Compat::Hash]] $pin = 200, ){ if $location { - validate_string($location) + validate_legacy(String, 'validate_string', $location) $_location = $location } if $release { - validate_string($release) + validate_legacy(String, 'validate_string', $release) $_release = $release } if $repos { - validate_string($repos) + validate_legacy(String, 'validate_string', $repos) $_repos = $repos } if $key { unless is_hash($key) { - validate_string($key) + validate_legacy(String, 'validate_string', $key) } $_key = $key } - if ($::apt::xfacts['lsbdistid'] == 'debian' or $::apt::xfacts['lsbdistid'] == 'ubuntu') { + if ($facts['lsbdistid'] == 'Debian' or $facts['lsbdistid'] == 'Ubuntu') { unless $location { $_location = $::apt::backports['location'] } unless $release { - $_release = "${::apt::xfacts['lsbdistcodename']}-backports" + $_release = "${facts['lsbdistcodename']}-backports" } unless $repos { $_repos = $::apt::backports['repos'] diff --git a/manifests/conf.pp b/manifests/conf.pp index 8cd9c64..364cae3 100644 --- a/manifests/conf.pp +++ b/manifests/conf.pp @@ -1,8 +1,8 @@ define apt::conf ( - $content = undef, - $ensure = present, - $priority = 50, - $notify_update = undef, + Optional[Variant[String, Stdlib::Compat::String]] $content = undef, + Enum['present', 'absent'] $ensure = present, + Variant[String, Stdlib::Compat::String, Integer, Stdlib::Compat::Integer] $priority = 50, + Optional[Boolean] $notify_update = undef, ) { unless $ensure == 'absent' { @@ -11,10 +11,11 @@ define apt::conf ( } } + $confheadertmp = epp('apt/_conf_header.epp') apt::setting { "conf-${name}": ensure => $ensure, priority => $priority, - content => template('apt/_conf_header.erb', 'apt/conf.erb'), + content => "${confheadertmp}${content}", notify_update => $notify_update, } } diff --git a/manifests/init.pp b/manifests/init.pp index 5664ede..40a40af 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -3,19 +3,40 @@ # Manage APT (Advanced Packaging Tool) # class apt ( - $confs = {}, - $update = {}, - $purge = {}, - $proxy = {}, - $sources = {}, - $keys = {}, - $ppas = {}, - $pins = {}, - $settings = {}, -) inherits ::apt::params { + Variant[Hash, Stdlib::Compat::Hash] $update_defaults, + Variant[Hash, Stdlib::Compat::Hash] $purge_defaults, + Variant[Hash, Stdlib::Compat::Hash] $proxy_defaults, + Variant[Hash, Stdlib::Compat::Hash] $include_defaults, + Variant[String, Stdlib::Compat::String] $provider, + Variant[String, Stdlib::Compat::String] $keyserver, + Optional[Variant[String, Stdlib::Compat::String]] $ppa_options, + Optional[Variant[String, Stdlib::Compat::String]] $ppa_package, + Optional[Variant[Hash, Stdlib::Compat::Hash]] $backports, + Variant[Hash, Stdlib::Compat::Hash] $confs = {}, + Variant[Hash, Stdlib::Compat::Hash] $update = {}, + Variant[Hash, Stdlib::Compat::Hash] $purge = {}, + Variant[Hash, Stdlib::Compat::Hash] $proxy = {}, + Variant[Hash, Stdlib::Compat::Hash] $sources = {}, + Variant[Hash, Stdlib::Compat::Hash] $keys = {}, + Variant[Hash, Stdlib::Compat::Hash] $ppas = {}, + Variant[Hash, Stdlib::Compat::Hash] $pins = {}, + Variant[Hash, Stdlib::Compat::Hash] $settings = {}, + Variant[String, Stdlib::Compat::String] $root = '/etc/apt', + Variant[String, Stdlib::Compat::String] $sources_list = "${root}/sources.list", + Variant[String, Stdlib::Compat::String] $sources_list_d = "${root}/sources.list.d", + Variant[String, Stdlib::Compat::String] $conf_d = "${root}/apt.conf.d", + Variant[String, Stdlib::Compat::String] $preferences = "${root}/preferences", + Variant[String, Stdlib::Compat::String] $preferences_d = "${root}/preferences.d", + Variant[Hash, Stdlib::Compat::Hash] $config_files = { conf => { path => $conf_d, ext => '' }, pref => { path => $preferences_d, ext => '.pref' }, list => { path => $sources_list_d, ext => '.list' } }, + Variant[Hash, Stdlib::Compat::Hash] $source_key_defaults = { 'server' => $keyserver, 'options' => undef, 'content' => undef, 'source' => undef }, +) { + + if $facts['osfamily'] != 'Debian' { + fail('This module only works on Debian or derivatives like Ubuntu') + } $frequency_options = ['always','daily','weekly','reluctantly'] - validate_hash($update) + validate_legacy(Hash, 'validate_hash', $update) if $update['frequency'] { validate_re($update['frequency'], $frequency_options) } @@ -33,18 +54,18 @@ class apt ( $_update = merge($::apt::update_defaults, $update) include ::apt::update - validate_hash($purge) + validate_legacy(Hash, 'validate_hash', $purge) if $purge['sources.list'] { - validate_bool($purge['sources.list']) + validate_legacy(Boolean, 'validate_bool', $purge['sources.list']) } if $purge['sources.list.d'] { - validate_bool($purge['sources.list.d']) + validate_legacy(Boolean, 'validate_bool', $purge['sources.list.d']) } if $purge['preferences'] { - validate_bool($purge['preferences']) + validate_legacy(Boolean, 'validate_bool', $purge['preferences']) } if $purge['preferences.d'] { - validate_bool($purge['preferences.d']) + validate_legacy(Boolean, 'validate_bool', $purge['preferences.d']) } $_purge = merge($::apt::purge_defaults, $purge) @@ -54,7 +75,7 @@ class apt ( validate_re($proxy['ensure'], ['file', 'present', 'absent']) } if $proxy['host'] { - validate_string($proxy['host']) + validate_legacy(String, 'validate_string', $proxy['host']) } if $proxy['port'] { unless is_integer($proxy['port']) { @@ -62,23 +83,27 @@ class apt ( } } if $proxy['https'] { - validate_bool($proxy['https']) + validate_legacy(Boolean, 'validate_bool', $proxy['https']) } $_proxy = merge($apt::proxy_defaults, $proxy) - validate_hash($confs) - validate_hash($sources) - validate_hash($keys) - validate_hash($settings) - validate_hash($ppas) - validate_hash($pins) + validate_legacy(Hash, 'validate_hash', $confs) + validate_legacy(Hash, 'validate_hash', $sources) + validate_legacy(Hash, 'validate_hash', $keys) + validate_legacy(Hash, 'validate_hash', $settings) + validate_legacy(Hash, 'validate_hash', $ppas) + validate_legacy(Hash, 'validate_hash', $pins) + + $confheadertmp = epp('apt/_conf_header.epp') + $proxytmp = epp('apt/proxy.epp', {'proxies' => $_proxy}) + $updatestamptmp = epp('apt/15update-stamp.epp') if $_proxy['ensure'] == 'absent' or $_proxy['host'] { apt::setting { 'conf-proxy': ensure => $_proxy['ensure'], priority => '01', - content => template('apt/_conf_header.erb', 'apt/proxy.erb'), + content => "${confheadertmp}${proxytmp}", } } @@ -100,7 +125,7 @@ class apt ( apt::setting { 'conf-update-stamp': priority => 15, - content => template('apt/_conf_header.erb', 'apt/15update-stamp.erb'), + content => "${confheadertmp}${updatestamptmp}", } file { 'sources.list': diff --git a/manifests/key.pp b/manifests/key.pp index d4a1d80..9a244b5 100644 --- a/manifests/key.pp +++ b/manifests/key.pp @@ -1,17 +1,17 @@ # == Define: apt::key define apt::key ( - $id = $title, - $ensure = present, - $content = undef, - $source = undef, - $server = $::apt::keyserver, - $options = undef, - $key = undef, - $key_content = undef, - $key_source = undef, - $key_server = undef, - $key_options = undef, -) { + Variant[String, Stdlib::Compat::String] $id = $title, + Enum['present', 'absent'] $ensure = present, + Optional[Variant[String, Stdlib::Compat::String]] $content = undef, + Optional[Variant[String, Stdlib::Compat::String]] $source = undef, + Variant[String, Stdlib::Compat::String] $server = $::apt::keyserver, + Optional[Variant[String, Stdlib::Compat::String]] $options = undef, + Optional[Variant[String, Stdlib::Compat::String, Hash, Stdlib::Compat::Hash]] $key = undef, + Optional[Variant[String, Stdlib::Compat::String]] $key_content = undef, + Optional[Variant[String, Stdlib::Compat::String]] $key_source = undef, + Optional[Variant[String, Stdlib::Compat::String]] $key_server = undef, + Optional[Variant[String, Stdlib::Compat::String]] $key_options = undef, + ) { if $key != undef { deprecation('apt $key', '$key is deprecated and will be removed in the next major release. Please use $id instead.') @@ -52,7 +52,7 @@ define apt::key ( validate_re($ensure, ['\A(absent|present)\Z',]) if $_content { - validate_string($_content) + validate_legacy(String, 'validate_string', $_content) } if $_source { @@ -64,7 +64,7 @@ define apt::key ( } if $_options { - validate_string($_options) + validate_legacy(String, 'validate_string', $_options) } case $ensure { @@ -81,8 +81,7 @@ define apt::key ( content => $_content, server => $_server, options => $_options, - } - -> anchor { "apt_key ${_id} present": } + } -> anchor { "apt_key ${_id} present": } } } @@ -99,8 +98,7 @@ define apt::key ( content => $_content, server => $_server, options => $_options, - } - -> anchor { "apt_key ${_id} absent": } + } -> anchor { "apt_key ${_id} absent": } } } diff --git a/manifests/params.pp b/manifests/params.pp deleted file mode 100644 index ea1087e..0000000 --- a/manifests/params.pp +++ /dev/null @@ -1,142 +0,0 @@ -class apt::params { - - if $::osfamily != 'Debian' { - fail('This module only works on Debian or derivatives like Ubuntu') - } - - # prior to puppet 3.5.0, defined() couldn't test if a variable was defined. - # strict_variables wasn't added until 3.5.0, so this should be fine. - if $::puppetversion and versioncmp($::puppetversion, '3.5.0') < 0 { - $xfacts = { - 'lsbdistcodename' => $::lsbdistcodename, - 'lsbdistrelease' => $::lsbdistrelease, - 'lsbdistid' => $::lsbdistid, - } - } else { - # Strict variables facts lookup compatibility - $xfacts = { - 'lsbdistcodename' => defined('$lsbdistcodename') ? { - true => $::lsbdistcodename, - default => undef, - }, - 'lsbdistrelease' => defined('$lsbdistrelease') ? { - true => $::lsbdistrelease, - default => undef, - }, - 'lsbdistid' => defined('$lsbdistid') ? { - true => $::lsbdistid, - default => undef, - }, - } - } - - $root = '/etc/apt' - $provider = '/usr/bin/apt-get' - $sources_list = "${root}/sources.list" - $sources_list_d = "${root}/sources.list.d" - $conf_d = "${root}/apt.conf.d" - $preferences = "${root}/preferences" - $preferences_d = "${root}/preferences.d" - $keyserver = 'keyserver.ubuntu.com' - - $config_files = { - 'conf' => { - 'path' => $conf_d, - 'ext' => '', - }, - 'pref' => { - 'path' => $preferences_d, - 'ext' => '.pref', - }, - 'list' => { - 'path' => $sources_list_d, - 'ext' => '.list', - } - } - - $update_defaults = { - 'frequency' => 'reluctantly', - 'timeout' => undef, - 'tries' => undef, - } - - $proxy_defaults = { - 'ensure' => undef, - 'host' => undef, - 'port' => 8080, - 'https' => false, - } - - $purge_defaults = { - 'sources.list' => false, - 'sources.list.d' => false, - 'preferences' => false, - 'preferences.d' => false, - } - - $source_key_defaults = { - 'server' => $keyserver, - 'options' => undef, - 'content' => undef, - 'source' => undef, - } - - $include_defaults = { - 'deb' => true, - 'src' => false, - } - - case $xfacts['lsbdistid'] { - 'debian': { - case $xfacts['lsbdistcodename'] { - 'squeeze': { - $backports = { - 'location' => 'http://httpredir.debian.org/debian-backports', - 'key' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - 'repos' => 'main contrib non-free', - } - } - default: { - $backports = { - 'location' => 'http://httpredir.debian.org/debian', - 'key' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - 'repos' => 'main contrib non-free', - } - } - } - - $ppa_options = undef - $ppa_package = undef - - } - 'ubuntu': { - $backports = { - 'location' => 'http://archive.ubuntu.com/ubuntu', - 'key' => '630239CC130E1A7FD81A27B140976EAF437D05B5', - 'repos' => 'main universe multiverse restricted', - } - - if $xfacts['lsbdistcodename'] == 'lucid' { - $ppa_options = undef - $ppa_package = 'python-software-properties' - } elsif $xfacts['lsbdistcodename'] == 'precise' { - $ppa_options = '-y' - $ppa_package = 'python-software-properties' - } elsif versioncmp($xfacts['lsbdistrelease'], '14.04') >= 0 { - $ppa_options = '-y' - $ppa_package = 'software-properties-common' - } else { - $ppa_options = '-y' - $ppa_package = 'python-software-properties' - } - } - undef: { - fail('Unable to determine lsbdistid, please install lsb-release first') - } - default: { - $ppa_options = undef - $ppa_package = undef - $backports = undef - } - } -} diff --git a/manifests/pin.pp b/manifests/pin.pp index dff2c29..5b9dc1d 100644 --- a/manifests/pin.pp +++ b/manifests/pin.pp @@ -2,23 +2,20 @@ # pin a release in apt, useful for unstable repositories define apt::pin( - $ensure = present, - $explanation = undef, - $order = 50, - $packages = '*', - $priority = 0, - $release = '', # a= - $origin = '', - $version = '', - $codename = '', # n= - $release_version = '', # v= - $component = '', # c= - $originator = '', # o= - $label = '' # l= + Optional[Enum['file', 'present', 'absent']] $ensure = present, + Optional[Variant[String, Stdlib::Compat::String]] $explanation = undef, + Variant[Integer, Stdlib::Compat::Integer] $order = 50, + Variant[String, Stdlib::Compat::String, Stdlib::Compat::Array, Array] $packages = '*', + Variant[Numeric, String, Stdlib::Compat::String] $priority = 0, + Optional[Variant[String, Stdlib::Compat::String]] $release = '', # a= + Optional[Variant[String, Stdlib::Compat::String]] $origin = '', + Optional[Variant[String, Stdlib::Compat::String]] $version = '', + Optional[Variant[String, Stdlib::Compat::String]] $codename = '', # n= + Optional[Variant[String, Stdlib::Compat::String]] $release_version = '', # v= + Optional[Variant[String, Stdlib::Compat::String]] $component = '', # c= + Optional[Variant[String, Stdlib::Compat::String]] $originator = '', # o= + Optional[Variant[String, Stdlib::Compat::String]] $label = '', # l= ) { - if $order and !is_integer($order) { - fail('Only integers are allowed in the apt::pin order param') - } if $explanation { $_explanation = $explanation @@ -36,7 +33,8 @@ define apt::pin( $release_version, $component, $originator, - $label] + $label, + ] $pin_release = join($pin_release_array, '') # Read the manpage 'apt_preferences(5)', especially the chapter @@ -71,10 +69,28 @@ define apt::pin( # be silently ignored. $file_name = regsubst($title, '[^0-9a-z\-_\.]', '_', 'IG') + $headertmp = epp('apt/_header.epp') + + $pinpreftmp = epp('apt/pin.pref.epp', { + 'name' => $name, + 'pin_release' => $pin_release, + 'release' => $release, + 'codename' => $codename, + 'release_version' => $release_version, + 'component' => $component, + 'originator' => $originator, + 'label' => $label, + 'version' => $version, + 'origin' => $origin, + 'explanation' => $_explanation, + 'packages_string' => $packages_string, + 'priority' => $priority, + }) + apt::setting { "pref-${file_name}": ensure => $ensure, priority => $order, - content => template('apt/_header.erb', 'apt/pin.pref.erb'), + content => "${headertmp}${pinpreftmp}", notify_update => false, } } diff --git a/manifests/ppa.pp b/manifests/ppa.pp index 6b025d7..adce47c 100644 --- a/manifests/ppa.pp +++ b/manifests/ppa.pp @@ -1,21 +1,21 @@ # ppa.pp define apt::ppa( - $ensure = 'present', - $options = $::apt::ppa_options, - $release = $::apt::xfacts['lsbdistcodename'], - $package_name = $::apt::ppa_package, - $package_manage = false, + Variant[String, Stdlib::Compat::String] $ensure = 'present', + Optional[Variant[String, Stdlib::Compat::String]] $options = $::apt::ppa_options, + Optional[Variant[String, Stdlib::Compat::String]] $release = $facts['lsbdistcodename'], + Optional[Variant[String, Stdlib::Compat::String]] $package_name = $::apt::ppa_package, + Boolean $package_manage = false, ) { unless $release { fail('lsbdistcodename fact not available: release parameter required') } - if $::apt::xfacts['lsbdistid'] == 'Debian' { + if $facts['lsbdistid'] == 'Debian' { fail('apt::ppa is not currently supported on Debian.') } - if versioncmp($::apt::xfacts['lsbdistrelease'], '15.10') >= 0 { - $distid = downcase($::apt::xfacts['lsbdistid']) + if versioncmp($facts['lsbdistrelease'], '15.10') >= 0 { + $distid = downcase($facts['lsbdistid']) $filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-${distid}-\\2-${release}") } else { $filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-\\2-${release}") @@ -28,7 +28,6 @@ define apt::ppa( if $ensure == 'present' { if $package_manage { ensure_packages($package_name) - $_require = [File['sources.list.d'], Package[$package_name]] } else { $_require = File['sources.list.d'] diff --git a/manifests/setting.pp b/manifests/setting.pp index b0fb62b..123bb2f 100644 --- a/manifests/setting.pp +++ b/manifests/setting.pp @@ -1,12 +1,12 @@ define apt::setting ( - $priority = 50, - $ensure = file, - $source = undef, - $content = undef, - $notify_update = true, + Variant[String, Stdlib::Compat::String, Integer, Stdlib::Compat::Integer, Array, Stdlib::Compat::Array] $priority = 50, + Optional[Enum['file', 'present', 'absent']] $ensure = file, + Optional[Variant[String, Stdlib::Compat::String]] $source = undef, + Optional[Variant[String, Stdlib::Compat::String]] $content = undef, + Optional[Boolean] $notify_update = true, + ) { - include 'apt::params' if $content and $source { fail('apt::setting cannot have both content and source') } @@ -15,8 +15,9 @@ define apt::setting ( fail('apt::setting needs either of content or source') } - validate_re($ensure, ['file', 'present', 'absent']) - validate_bool($notify_update) + if $notify_update { + validate_legacy(Boolean, 'validate_bool', $notify_update) + } $title_array = split($title, '-') $setting_type = $title_array[0] @@ -30,11 +31,11 @@ define apt::setting ( } if $source { - validate_string($source) + validate_legacy(String, 'validate_string', $source) } if $content { - validate_string($content) + validate_legacy(String, 'validate_string', $content) } if ($setting_type == 'list') or ($setting_type == 'pref') { @@ -43,8 +44,8 @@ define apt::setting ( $_priority = $priority } - $_path = $::apt::params::config_files[$setting_type]['path'] - $_ext = $::apt::params::config_files[$setting_type]['ext'] + $_path = $::apt::config_files[$setting_type]['path'] + $_ext = $::apt::config_files[$setting_type]['ext'] if $notify_update { $_notify = Class['apt::update'] diff --git a/manifests/source.pp b/manifests/source.pp index 5b8e4b1..8db3b28 100644 --- a/manifests/source.pp +++ b/manifests/source.pp @@ -1,46 +1,39 @@ # source.pp # add an apt source define apt::source( - $location = undef, - $comment = $name, - $ensure = present, - $release = undef, - $repos = 'main', - $include = {}, - $key = undef, - $pin = undef, - $architecture = undef, - $allow_unsigned = false, - $include_src = undef, - $include_deb = undef, - $required_packages = undef, - $key_server = undef, - $key_content = undef, - $key_source = undef, - $trusted_source = undef, - $notify_update = true, + Optional[Variant[String, Stdlib::Compat::String]] $location = undef, + Variant[String, Stdlib::Compat::String] $comment = $name, + Variant[String, Stdlib::Compat::String] $ensure = present, + Optional[Variant[String, Stdlib::Compat::String]] $release = undef, + Variant[String, Stdlib::Compat::String] $repos = 'main', + Optional[Variant[Hash, Stdlib::Compat::Hash]] $include = {}, + Optional[Variant[String, Stdlib::Compat::String, Hash, Stdlib::Compat::Hash]] $key = undef, + $pin = undef, + Optional[Variant[String, Stdlib::Compat::String]] $architecture = undef, + Boolean $allow_unsigned = false, + Boolean $notify_update = true, + Optional[Variant[String, Stdlib::Compat::String]] $key_server = undef, + Optional[Variant[String, Stdlib::Compat::String]] $key_content = undef, + Optional[Variant[String, Stdlib::Compat::String]] $key_source = undef, + Optional[Boolean] $include_src = undef, + Optional[Boolean] $include_deb = undef, + $required_packages = undef, + $trusted_source = undef, ) { - validate_string($architecture, $comment, $location, $repos) - validate_bool($allow_unsigned) - validate_hash($include) + + validate_legacy(String, 'validate_string', $architecture, $comment, $location, $repos) + validate_legacy(Boolean, 'validate_bool', $allow_unsigned) + validate_legacy(Hash, 'validate_hash', $include) # This is needed for compat with 1.8.x include ::apt $_before = Apt::Setting["list-${title}"] - if $include_src != undef { - deprecation('apt $include_src', "\$include_src is deprecated and will be removed in the next major release, please use \$include => { 'src' => ${include_src} } instead") - } - - if $include_deb != undef { - deprecation('apt $include_deb', "\$include_deb is deprecated and will be removed in the next major release, please use \$include => { 'deb' => ${include_deb} } instead") - } - if $required_packages != undef { deprecation('apt $required_packages', '$required_packages is deprecated and will be removed in the next major release, please use package resources instead.') exec { "Required packages: '${required_packages}' for ${name}": - command => "${::apt::params::provider} -y install ${required_packages}", + command => "${::apt::provider} -y install ${required_packages}", logoutput => 'on_failure', refreshonly => true, tries => 3, @@ -49,18 +42,6 @@ define apt::source( } } - if $key_server != undef { - deprecation('apt $key_server', "\$key_server is deprecated and will be removed in the next major release, please use \$key => { 'server' => ${key_server} } instead.") - } - - if $key_content != undef { - deprecation('apt $key_content', "\$key_content is deprecated and will be removed in the next major release, please use \$key => { 'content' => ${key_content} } instead.") - } - - if $key_source != undef { - deprecation('apt $key_source', "\$key_source is deprecated and will be removed in the next major release, please use \$key => { 'source' => ${key_source} } instead.") - } - if $trusted_source != undef { deprecation('apt $trusted_source', '$trusted_source is deprecated and will be removed in the next major release, please use $allow_unsigned instead.') $_allow_unsigned = $trusted_source @@ -69,8 +50,9 @@ define apt::source( } if ! $release { - $_release = $::apt::params::xfacts['lsbdistcodename'] - unless $_release { + if $facts['lsbdistcodename'] { + $_release = $facts['lsbdistcodename'] + } else { fail('lsbdistcodename fact not available: release parameter required') } } else { @@ -94,7 +76,7 @@ define apt::source( $_deprecated_include = {} } - $_include = merge($::apt::params::include_defaults, $_deprecated_include, $include) + $includes = merge($::apt::include_defaults, $_deprecated_include, $include) $_deprecated_key = { 'key_server' => $key_server, @@ -107,16 +89,28 @@ define apt::source( unless $key['id'] { fail('key hash must contain at least an id entry') } - $_key = merge($::apt::params::source_key_defaults, $_deprecated_key, $key) + $_key = merge($::apt::source_key_defaults, $_deprecated_key, $key) } else { - validate_string($key) + validate_legacy(String, 'validate_string', $key) $_key = merge( { 'id' => $key }, $_deprecated_key) } } + $header = epp('apt/_header.epp') + + $sourcelist = epp('apt/source.list.epp', { + 'comment' => $comment, + 'includes' => $includes, + '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'), + content => "${header}${sourcelist}", notify_update => $notify_update, } diff --git a/metadata.json b/metadata.json index 4f3875b..c4f9bb7 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-apt", - "version": "2.4.0", + "version": "3.0.0", "author": "Puppet Labs", "summary": "Provides an interface for managing Apt source, key, and definitions with Puppet", "license": "Apache-2.0", @@ -8,8 +8,9 @@ "project_page": "https://github.com/puppetlabs/puppetlabs-apt", "issues_url": "https://tickets.puppetlabs.com/browse/MODULES", "dependencies": [ - {"name":"puppetlabs/stdlib","version_requirement":">= 4.13.0 < 5.0.0"} + {"name":"puppetlabs/stdlib","version_requirement":">= 4.16.0 < 5.0.0"} ], + "data_provider": "hiera", "operatingsystem_support": [ { "operatingsystem": "Debian", @@ -32,7 +33,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 3.0.0 < 5.0.0" + "version_requirement": ">= 4.7.0 < 5.0.0" } ] } diff --git a/spec/classes/apt_backports_spec.rb b/spec/classes/apt_backports_spec.rb index 5762025..5c65b57 100644 --- a/spec/classes/apt_backports_spec.rb +++ b/spec/classes/apt_backports_spec.rb @@ -7,6 +7,7 @@ describe 'apt::backports', :type => :class do context 'defaults on deb' do let(:facts) do { + :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', @@ -25,6 +26,7 @@ describe 'apt::backports', :type => :class do context 'defaults on squeeze' do let(:facts) do { + :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '6', :full => '6.0' }}, :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'squeeze', @@ -43,6 +45,7 @@ describe 'apt::backports', :type => :class do context 'defaults on ubuntu' do let(:facts) do { + :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, :lsbdistid => 'Ubuntu', :osfamily => 'Debian', :lsbdistcodename => 'trusty', @@ -90,6 +93,7 @@ describe 'apt::backports', :type => :class do context 'set things with hashes' do let(:facts) do { + :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, :lsbdistid => 'Ubuntu', :osfamily => 'Debian', :lsbdistcodename => 'trusty', @@ -217,7 +221,7 @@ describe 'apt::backports', :type => :class do it do expect { subject.call - }.to raise_error(Puppet::Error, /is not a string/) + }.to raise_error(Puppet::Error, /expects a String value/) end end context 'invalid release' do @@ -229,7 +233,7 @@ describe 'apt::backports', :type => :class do it do expect { subject.call - }.to raise_error(Puppet::Error, /is not a string/) + }.to raise_error(Puppet::Error, /expects a String value/) end end context 'invalid repos' do @@ -241,7 +245,7 @@ describe 'apt::backports', :type => :class do it do expect { subject.call - }.to raise_error(Puppet::Error, /is not a string/) + }.to raise_error(Puppet::Error, /expects a String value/) end end context 'invalid key' do @@ -253,7 +257,7 @@ describe 'apt::backports', :type => :class do it do expect { subject.call - }.to raise_error(Puppet::Error, /is not a string/) + }.to raise_error(Puppet::Error, /expects a value of type String, Hash,/) end end context 'invalid pin' do @@ -265,7 +269,7 @@ describe 'apt::backports', :type => :class do it do expect { subject.call - }.to raise_error(Puppet::Error, /pin must be either a string, number or hash/) + }.to raise_error(Puppet::Error, /parameter 'pin' expects a value of type Integer, Pattern/) end end end diff --git a/spec/classes/apt_spec.rb b/spec/classes/apt_spec.rb index 53ef7be..8ecf418 100644 --- a/spec/classes/apt_spec.rb +++ b/spec/classes/apt_spec.rb @@ -1,7 +1,12 @@ require 'spec_helper' describe 'apt' do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => Puppet.version} } - + let(:facts) do + { :lsbdistid => 'Debian', + :osfamily => 'Debian', + :lsbdistcodename => 'wheezy', + :puppetversion => Puppet.version, + } + end context 'defaults' do it { is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with({ :ensure => 'file', @@ -137,9 +142,11 @@ describe 'apt' do context 'with sources defined on valid osfamily' do let :facts do - { :osfamily => 'Debian', + { :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '12', :full => '12.04' }}, + :osfamily => 'Debian', :lsbdistcodename => 'precise', - :lsbdistid => 'Debian', + :lsbdistid => 'Ubuntu', + :lsbdistrelease => '12.04', :puppetversion => Puppet.version, } end diff --git a/spec/classes/params_spec.rb b/spec/classes/params_spec.rb deleted file mode 100644 index 3161cf0..0000000 --- a/spec/classes/params_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'spec_helper' -describe 'apt::params', :type => :class do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => Puppet.version, } } - - # There are 4 resources in this class currently - # there should not be any more resources because it is a params class - # The resources are class[apt::params], class[main], class[settings], stage[main] - it "Should not contain any resources" do - expect(subject.call.resources.size).to eq(4) - end - - describe "With lsb-release not installed" do - let(:facts) { { :osfamily => 'Debian', :puppetversion => Puppet.version, } } - let (:title) { 'my_package' } - - it do - expect { - subject.call - }.to raise_error(Puppet::Error, /Unable to determine lsbdistid, please install lsb-release first/) - end - end -end diff --git a/spec/defines/key_compat_spec.rb b/spec/defines/key_compat_spec.rb index eaf53fc..02b9754 100644 --- a/spec/defines/key_compat_spec.rb +++ b/spec/defines/key_compat_spec.rb @@ -248,7 +248,7 @@ describe 'apt::key', :type => :define do :key_content => [], } end it 'fails' do - expect { subject.call }.to raise_error(/is not a string/) + expect { subject.call }.to raise_error(/expects a String value/) end end @@ -266,7 +266,7 @@ describe 'apt::key', :type => :define do :key_options => {}, } end it 'fails' do - expect { subject.call }.to raise_error(/is not a string/) + expect { subject.call }.to raise_error(/expects a String value/) end end @@ -277,7 +277,7 @@ describe 'apt::key', :type => :define do } end it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(/a match for Enum\['absent', 'present'\], got 'foo'/) end end diff --git a/spec/defines/key_spec.rb b/spec/defines/key_spec.rb index 1ebcfc7..a7334d8 100644 --- a/spec/defines/key_spec.rb +++ b/spec/defines/key_spec.rb @@ -245,7 +245,7 @@ describe 'apt::key' do :content => [], } end it 'fails' do - expect { subject.call }.to raise_error(/is not a string/) + expect { subject.call }.to raise_error(/expects a String value/) end end @@ -263,7 +263,7 @@ describe 'apt::key' do :options => {}, } end it 'fails' do - expect { subject.call }.to raise_error(/is not a string/) + expect { subject.call }.to raise_error(/expects a String value/) end end @@ -275,7 +275,7 @@ describe 'apt::key' do } end it 'fails' do - expect { subject.call }.to raise_error(/does not match/) + expect { subject.call }.to raise_error(/for Enum\['absent', 'present'\], got/) end end end diff --git a/spec/defines/pin_spec.rb b/spec/defines/pin_spec.rb index 9fb28c6..550d89e 100644 --- a/spec/defines/pin_spec.rb +++ b/spec/defines/pin_spec.rb @@ -8,18 +8,16 @@ describe 'apt::pin', :type => :define do context 'defaults' do it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n/)} - it { is_expected.to contain_apt__setting("pref-my_pin") } end context 'set version' do let :params do { 'packages' => 'vim', - 'version' => '1', + 'version' => "1", } end it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n/)} - it { is_expected.to contain_apt__setting("pref-my_pin") } end context 'set origin' do @@ -30,7 +28,6 @@ describe 'apt::pin', :type => :define do } end it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n/)} - it { is_expected.to contain_apt__setting("pref-my_pin") } end context 'not defaults' do @@ -81,7 +78,7 @@ describe 'apt::pin', :type => :define do it do expect { subject.call - }.to raise_error(Puppet::Error, /Only integers are allowed/) + }.to raise_error(Puppet::Error, /expects a value of type Integer/) end end diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index a4c3014..ae66087 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -7,6 +7,7 @@ describe 'apt::ppa' do describe 'defaults' do let :facts do { + :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }}, :lsbdistrelease => '11.04', :lsbdistcodename => 'natty', :operatingsystem => 'Ubuntu', @@ -31,6 +32,7 @@ describe 'apt::ppa' do describe 'Ubuntu 15.10 sources.list filename' do let :facts do { + :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '15', :full => '15.10' }}, :lsbdistrelease => '15.10', :lsbdistcodename => 'wily', :operatingsystem => 'Ubuntu', @@ -69,6 +71,7 @@ describe 'apt::ppa' do end let :facts do { + :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }}, :lsbdistrelease => '11.04', :lsbdistcodename => 'natty', :operatingsystem => 'Ubuntu', @@ -104,6 +107,7 @@ describe 'apt::ppa' do end let :facts do { + :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }}, :lsbdistrelease => '11.04', :lsbdistcodename => 'natty', :operatingsystem => 'Ubuntu', @@ -141,6 +145,7 @@ describe 'apt::ppa' do end let :facts do { + :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }}, :lsbdistrelease => '11.04', :lsbdistcodename => 'natty', :operatingsystem => 'Ubuntu', @@ -180,6 +185,7 @@ describe 'apt::ppa' do end let :facts do { + :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, :lsbdistrelease => '14.04', :lsbdistcodename => 'trusty', :operatingsystem => 'Ubuntu', @@ -216,6 +222,7 @@ describe 'apt::ppa' do end let :facts do { + :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, :lsbdistrelease => '14.04', :lsbdistcodename => 'trusty', :operatingsystem => 'Ubuntu', @@ -250,6 +257,7 @@ describe 'apt::ppa' do end let :facts do { + :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, :lsbdistrelease => '14.04', :lsbdistcodename => 'trusty', :operatingsystem => 'Ubuntu', @@ -284,6 +292,7 @@ describe 'apt::ppa' do end let :facts do { + :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }}, :lsbdistrelease => '14.04', :lsbdistcodename => 'trusty', :operatingsystem => 'Ubuntu', diff --git a/spec/defines/setting_spec.rb b/spec/defines/setting_spec.rb index c0aad8e..bf361fa 100644 --- a/spec/defines/setting_spec.rb +++ b/spec/defines/setting_spec.rb @@ -2,7 +2,17 @@ require 'spec_helper' describe 'apt::setting' do let(:pre_condition) { 'class { "apt": }' } - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => Puppet.version, } } + let :facts do + { + :os => { :distro => { :codename => 'wheezy' }, :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, + :lsbdistrelease => '7.0', + :lsbdistcodename => 'wheezy', + :operatingsystem => 'Debian', + :osfamily => 'Debian', + :lsbdistid => 'Debian', + :puppetversion => Puppet.version, + } + end let(:title) { 'conf-teddybear' } let(:default_params) { { :content => 'di' } } @@ -82,21 +92,21 @@ describe 'apt::setting' do let(:title) { 'ext-teddybear' } let(:params) { default_params } it do - expect { subject.call }.to raise_error(Puppet::Error, /must start with /) + expect { subject.call }.to raise_error(Puppet::Error, /must start with either/) end end context 'with ensure=banana' do let(:params) { default_params.merge({ :ensure => 'banana' }) } it do - expect { subject.call }.to raise_error(Puppet::Error, /"banana" does not /) + expect { subject.call }.to raise_error(Puppet::Error, /Enum\['absent', 'file', 'present'\], got 'banana'/) end end context 'with priority=1.2' do let(:params) { default_params.merge({ :priority => 1.2 }) } if Puppet::Util::Package.versioncmp(Puppet.version, '4.0') >= 0 || ENV["FUTURE_PARSER"] == 'yes' - it { is_expected.to compile.and_raise_error(/input needs to be a String/) } + it { is_expected.to compile.and_raise_error(/expects a value of type/) } else it { is_expected.to compile.and_raise_error(/priority must be an integer or a zero-padded integer/) } end diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index bf6977a..b89a4f0 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -15,9 +15,9 @@ describe 'apt::source' do context 'without location' do let :facts do { - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', + :os => { :family => 'Debian' }, :osfamily => 'Debian', + :lsbdistcodename => 'wheezy', :puppetversion => Puppet.version, } end @@ -48,9 +48,12 @@ describe 'apt::source' do describe 'no defaults' do let :facts do { + :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }}, :lsbdistid => 'Debian', :lsbdistcodename => 'wheezy', :osfamily => 'Debian', + :operatingsystem => 'Debian', + :lsbdistrelease => '7.0', :puppetversion => Puppet.version, } end diff --git a/templates/15update-stamp.erb b/templates/15update-stamp.epp similarity index 100% rename from templates/15update-stamp.erb rename to templates/15update-stamp.epp diff --git a/templates/_conf_header.erb b/templates/_conf_header.epp similarity index 100% rename from templates/_conf_header.erb rename to templates/_conf_header.epp diff --git a/templates/_header.erb b/templates/_header.epp similarity index 100% rename from templates/_header.erb rename to templates/_header.epp diff --git a/templates/conf.erb b/templates/conf.erb deleted file mode 100644 index a35d1d4..0000000 --- a/templates/conf.erb +++ /dev/null @@ -1 +0,0 @@ -<%= @content -%> diff --git a/templates/pin.pref.epp b/templates/pin.pref.epp new file mode 100644 index 0000000..7991332 --- /dev/null +++ b/templates/pin.pref.epp @@ -0,0 +1,26 @@ +<%- | $name, $pin_release, $release, $codename, $release_version, $component, $originator, $label, $version, $origin, $explanation, $packages_string, $priority | -%> +<%- +$pin = +if $pin_release.length > 0 { + $options = [ + if $release { "a=${release}" }, + if $codename { "n=${codename}" }, + if $release_version { "v=${release_version}"}, + if $component { "c=${component}" }, + if $originator { "o=${originator}" }, + if $label { "l=${label}" }, + ].filter |$x| { $x != undef } + "release ${options.join(', ')}" } + +elsif $version and "${version}".length > 0 { + "version ${version}" } +elsif $origin and $origin.length > 0 { + "origin ${origin}" } +else { + "release a=${name}" #Default value +} +-%> +Explanation: <%= $explanation %> +Package: <%= $packages_string %> +Pin: <%= $pin %> +Pin-Priority: <%= $priority %> diff --git a/templates/pin.pref.erb b/templates/pin.pref.erb deleted file mode 100644 index 76936d7..0000000 --- a/templates/pin.pref.erb +++ /dev/null @@ -1,21 +0,0 @@ -<%- -@pin = "release a=#{@name}" # default value -if @pin_release.length > 0 - options = [] - options.push("a=#{@release}") if @release.length > 0 - options.push("n=#{@codename}") if @codename.length > 0 - options.push("v=#{@release_version}") if @release_version.length > 0 - options.push("c=#{@component}") if @component.length > 0 - options.push("o=#{@originator}") if @originator.length > 0 - options.push("l=#{@label}") if @label.length > 0 - @pin = "release #{options.join(', ')}" -elsif @version.length > 0 - @pin = "version #{@version}" -elsif @origin.length > 0 - @pin = "origin #{@origin}" -end --%> -Explanation: <%= @_explanation %> -Package: <%= @packages_string %> -Pin: <%= @pin %> -Pin-Priority: <%= @priority %> diff --git a/templates/proxy.epp b/templates/proxy.epp new file mode 100644 index 0000000..0cbccb8 --- /dev/null +++ b/templates/proxy.epp @@ -0,0 +1,5 @@ +<%- | Hash $proxies | -%> +Acquire::http::proxy "http://<%= $proxies['host'] %>:<%= $proxies['port'] %>/"; +<%- if $proxies['https'] { %> +Acquire::https::proxy "https://<%= $proxies['host'] %>:<%= $proxies['port'] %>/"; +<%- } -%> diff --git a/templates/proxy.erb b/templates/proxy.erb deleted file mode 100644 index 670e3a7..0000000 --- a/templates/proxy.erb +++ /dev/null @@ -1,4 +0,0 @@ -Acquire::http::proxy "http://<%= @_proxy['host'] %>:<%= @_proxy['port'] %>/"; -<%- if @_proxy['https'] %> -Acquire::https::proxy "https://<%= @_proxy['host'] %>:<%= @_proxy['port'] %>/"; -<%- end -%> diff --git a/templates/source.list.epp b/templates/source.list.epp new file mode 100644 index 0000000..727766c --- /dev/null +++ b/templates/source.list.epp @@ -0,0 +1,10 @@ +<%- | String $comment, Hash $includes, $architecture, Boolean $allow_unsigned, $location, $release, String $repos | -%> +# <%= $comment %> +<%- if $includes['deb'] { -%> +deb <%- if ($architecture or $allow_unsigned) {-%> + [<%- if ($architecture) {%>arch=<%= $architecture %><% } %><%if ($architecture and $allow_unsigned) {%> <% }%><% if ($allow_unsigned) {%>trusted=yes<% } %>] <%- } %> <%= $location %> <%= $release %> <%= $repos %> +<%- } -%> +<%- if $includes['src'] { -%> +deb-src <%- if $architecture or $allow_unsigned { -%> + [<%- if ($architecture) {%>arch=<%= $architecture %><% } %><%if ($architecture and $allow_unsigned) {%> <% }%><% if ($allow_unsigned) {%>trusted=yes<% } %>] <%- } %> <%= $location %> <%= $release %> <%= $repos %> +<%- } -%> diff --git a/templates/source.list.erb b/templates/source.list.erb deleted file mode 100644 index 84cd2cf..0000000 --- a/templates/source.list.erb +++ /dev/null @@ -1,9 +0,0 @@ -# <%= @comment %> -<%- if @_include['deb'] then -%> -deb <%- if @architecture or @_allow_unsigned -%> -[<%- if @architecture %>arch=<%= @architecture %><% end %><%if @architecture and @_allow_unsigned %> <% end%><% if @_allow_unsigned %>trusted=yes<% end %>] <%- end %><%= @location %> <%= @_release %> <%= @repos %> -<%- end -%> -<%- if @_include['src'] then -%> -deb-src <%- if @architecture or @_allow_unsigned -%> -[<%- if @architecture %>arch=<%= @architecture %><% end %><%if @architecture and @_allow_unsigned %> <% end%><% if @_allow_unsigned %>trusted=yes<% end %>] <%- end %><%= @location %> <%= @_release %> <%= @repos %> -<%- end -%> -- 2.45.2