+## 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.
--- /dev/null
+---
+#Squeeze
+apt::backports: { location: 'http://httpredir.debian.org/debian-backports', key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', repos: 'main contrib non-free' }
+apt::ppa_options: ~
+apt::ppa_package: ~
--- /dev/null
+---
+apt::backports: { location: 'http://httpredir.debian.org/debian', key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', repos: 'main contrib non-free' }
+apt::ppa_options: ~
+apt::ppa_package: ~
--- /dev/null
+---
+#Lucid
+apt::ppa_options: ~
+apt::ppa_package: 'python-software-properties'
--- /dev/null
+---
+#Precise
+apt::ppa_options: '-y'
+apt::ppa_package: 'python-software-properties'
--- /dev/null
+---
+#Trusty
+apt::ppa_options: '-y'
+apt::ppa_package: 'software-properties-common'
--- /dev/null
+---
+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'
--- /dev/null
+---
+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: ~
--- /dev/null
+---
+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
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']
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' {
}
}
+ $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,
}
}
# 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)
}
$_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)
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']) {
}
}
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}",
}
}
apt::setting { 'conf-update-stamp':
priority => 15,
- content => template('apt/_conf_header.erb', 'apt/15update-stamp.erb'),
+ content => "${confheadertmp}${updatestamptmp}",
}
file { 'sources.list':
# == 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.')
validate_re($ensure, ['\A(absent|present)\Z',])
if $_content {
- validate_string($_content)
+ validate_legacy(String, 'validate_string', $_content)
}
if $_source {
}
if $_options {
- validate_string($_options)
+ validate_legacy(String, 'validate_string', $_options)
}
case $ensure {
content => $_content,
server => $_server,
options => $_options,
- }
- -> anchor { "apt_key ${_id} present": }
+ } -> anchor { "apt_key ${_id} present": }
}
}
content => $_content,
server => $_server,
options => $_options,
- }
- -> anchor { "apt_key ${_id} absent": }
+ } -> anchor { "apt_key ${_id} absent": }
}
}
+++ /dev/null
-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
- }
- }
-}
# 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
$release_version,
$component,
$originator,
- $label]
+ $label,
+ ]
$pin_release = join($pin_release_array, '')
# Read the manpage 'apt_preferences(5)', especially the chapter
# 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,
}
}
# 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}")
if $ensure == 'present' {
if $package_manage {
ensure_packages($package_name)
-
$_require = [File['sources.list.d'], Package[$package_name]]
} else {
$_require = File['sources.list.d']
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')
}
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]
}
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') {
$_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']
# 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,
}
}
- 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
}
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 {
$_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,
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,
}
{
"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",
"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",
"requirements": [
{
"name": "puppet",
- "version_requirement": ">= 3.0.0 < 5.0.0"
+ "version_requirement": ">= 4.7.0 < 5.0.0"
}
]
}
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',
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',
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',
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',
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
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
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
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
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
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',
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
+++ /dev/null
-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
: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
: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
}
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
: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
: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
}
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
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
}
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
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
describe 'defaults' do
let :facts do
{
+ :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }},
:lsbdistrelease => '11.04',
:lsbdistcodename => 'natty',
:operatingsystem => 'Ubuntu',
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',
end
let :facts do
{
+ :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }},
:lsbdistrelease => '11.04',
:lsbdistcodename => 'natty',
:operatingsystem => 'Ubuntu',
end
let :facts do
{
+ :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }},
:lsbdistrelease => '11.04',
:lsbdistcodename => 'natty',
:operatingsystem => 'Ubuntu',
end
let :facts do
{
+ :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }},
:lsbdistrelease => '11.04',
:lsbdistcodename => 'natty',
:operatingsystem => 'Ubuntu',
end
let :facts do
{
+ :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
:lsbdistrelease => '14.04',
:lsbdistcodename => 'trusty',
:operatingsystem => 'Ubuntu',
end
let :facts do
{
+ :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
:lsbdistrelease => '14.04',
:lsbdistcodename => 'trusty',
:operatingsystem => 'Ubuntu',
end
let :facts do
{
+ :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
:lsbdistrelease => '14.04',
:lsbdistcodename => 'trusty',
:operatingsystem => 'Ubuntu',
end
let :facts do
{
+ :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
:lsbdistrelease => '14.04',
:lsbdistcodename => 'trusty',
:operatingsystem => 'Ubuntu',
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' } }
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
context 'without location' do
let :facts do
{
- :lsbdistid => 'Debian',
- :lsbdistcodename => 'wheezy',
+ :os => { :family => 'Debian' },
:osfamily => 'Debian',
+ :lsbdistcodename => 'wheezy',
:puppetversion => Puppet.version,
}
end
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
+++ /dev/null
-<%= @content -%>
--- /dev/null
+<%- | $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 %>
+++ /dev/null
-<%-
-@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 %>
--- /dev/null
+<%- | Hash $proxies | -%>
+Acquire::http::proxy "http://<%= $proxies['host'] %>:<%= $proxies['port'] %>/";
+<%- if $proxies['https'] { %>
+Acquire::https::proxy "https://<%= $proxies['host'] %>:<%= $proxies['port'] %>/";
+<%- } -%>
+++ /dev/null
-Acquire::http::proxy "http://<%= @_proxy['host'] %>:<%= @_proxy['port'] %>/";
-<%- if @_proxy['https'] %>
-Acquire::https::proxy "https://<%= @_proxy['host'] %>:<%= @_proxy['port'] %>/";
-<%- end -%>
--- /dev/null
+<%- | 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 %>
+<%- } -%>
+++ /dev/null
-# <%= @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 -%>