Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First Release prep for Puppet 4 language update #667

Merged
merged 1 commit into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
5 changes: 5 additions & 0 deletions data/Debian-6.0.yaml
Original file line number Diff line number Diff line change
@@ -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: ~
4 changes: 4 additions & 0 deletions data/Debian.yaml
Original file line number Diff line number Diff line change
@@ -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: ~
4 changes: 4 additions & 0 deletions data/Ubuntu-10.04.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
#Lucid
apt::ppa_options: ~
apt::ppa_package: 'python-software-properties'
4 changes: 4 additions & 0 deletions data/Ubuntu-12.04.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
#Precise
apt::ppa_options: '-y'
apt::ppa_package: 'python-software-properties'
4 changes: 4 additions & 0 deletions data/Ubuntu-14.04.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
#Trusty
apt::ppa_options: '-y'
apt::ppa_package: 'software-properties-common'
4 changes: 4 additions & 0 deletions data/Ubuntu.yaml
Original file line number Diff line number Diff line change
@@ -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'
11 changes: 11 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -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: ~
22 changes: 22 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 11 additions & 11 deletions manifests/backports.pp
Original file line number Diff line number Diff line change
@@ -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']
Expand Down
11 changes: 6 additions & 5 deletions manifests/conf.pp
Original file line number Diff line number Diff line change
@@ -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' {
Expand All @@ -11,10 +11,11 @@
}
}

$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,
}
}
77 changes: 51 additions & 26 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -33,18 +54,18 @@
$_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)
Expand All @@ -54,31 +75,35 @@
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']) {
fail('$proxy port must be an integer')
}
}
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}",
}
}

Expand All @@ -100,7 +125,7 @@

apt::setting { 'conf-update-stamp':
priority => 15,
content => template('apt/_conf_header.erb', 'apt/15update-stamp.erb'),
content => "${confheadertmp}${updatestamptmp}",
}

file { 'sources.list':
Expand Down
34 changes: 16 additions & 18 deletions manifests/key.pp
Original file line number Diff line number Diff line change
@@ -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.')
Expand Down Expand Up @@ -52,7 +52,7 @@
validate_re($ensure, ['\A(absent|present)\Z',])

if $_content {
validate_string($_content)
validate_legacy(String, 'validate_string', $_content)
}

if $_source {
Expand All @@ -64,7 +64,7 @@
}

if $_options {
validate_string($_options)
validate_legacy(String, 'validate_string', $_options)
}

case $ensure {
Expand All @@ -81,8 +81,7 @@
content => $_content,
server => $_server,
options => $_options,
}
-> anchor { "apt_key ${_id} present": }
} -> anchor { "apt_key ${_id} present": }
}
}

Expand All @@ -99,8 +98,7 @@
content => $_content,
server => $_server,
options => $_options,
}
-> anchor { "apt_key ${_id} absent": }
} -> anchor { "apt_key ${_id} absent": }
}
}

Expand Down
Loading