summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.fixtures.yml6
-rw-r--r--.gitignore5
-rw-r--r--.gitlab-ci.yml39
-rw-r--r--Gemfile4
-rw-r--r--manifests/apt_conf.pp19
-rw-r--r--manifests/apticron.pp26
-rw-r--r--manifests/config.pp89
-rw-r--r--manifests/cron/dist_upgrade.pp15
-rw-r--r--manifests/dist_upgrade.pp3
-rw-r--r--manifests/dist_upgrade/initiator.pp9
-rw-r--r--manifests/dot_d_directories.pp9
-rw-r--r--manifests/dselect.pp5
-rw-r--r--manifests/init.pp131
-rw-r--r--manifests/install.pp11
-rw-r--r--manifests/key.pp2
-rw-r--r--manifests/key/plain.pp2
-rw-r--r--manifests/listchanges.pp21
-rw-r--r--manifests/params.pp18
-rw-r--r--manifests/preferences.pp1
-rw-r--r--manifests/preferences_snippet.pp28
-rw-r--r--manifests/preseeded_package.pp8
-rw-r--r--manifests/proxy_client.pp8
-rw-r--r--manifests/reboot_required_notify.pp1
-rw-r--r--manifests/reboot_required_notify/jessie.pp3
-rw-r--r--manifests/reboot_required_notify/wheezy.pp1
-rw-r--r--manifests/sources_list.pp13
-rw-r--r--manifests/unattended_upgrades.pp18
-rw-r--r--manifests/update.pp3
-rw-r--r--manifests/upgrade_package.pp12
-rw-r--r--spec/classes/init_spec.rb18
-rw-r--r--spec/defines/conf_spec.rb74
-rw-r--r--spec/defines/preferences_snippet_spec.rb66
-rw-r--r--spec/spec_helper.rb12
33 files changed, 442 insertions, 238 deletions
diff --git a/.fixtures.yml b/.fixtures.yml
new file mode 100644
index 0000000..99efd66
--- /dev/null
+++ b/.fixtures.yml
@@ -0,0 +1,6 @@
+fixtures:
+ repositories:
+ "common":
+ "repo": "https://gitlab.com/shared-puppet-modules-group/common.git"
+ symlinks:
+ "apt": "#{source_dir}"
diff --git a/.gitignore b/.gitignore
index 3b626b8..ad8ff1f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,10 +1,7 @@
/pkg/
/Gemfile.lock
/vendor/
-/spec/fixtures/manifests/*
-/spec/fixtures/modules/*
-!/spec/fixtures/modules/apt
-!/spec/fixtures/modules/apt/*
+/spec/fixtures
/log
/.vagrant/
/.bundle/
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 2f381cd..49bf2e3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,13 +1,42 @@
image: leapcode/ruby
before_script:
- - ruby -v
- - sudo gem install bundler --no-ri --no-rdoc
- - sudo bundle install --jobs $(nproc) --without system_tests --path=/var/cache/gitlab-runner/ "${FLAGS[@]}"
+ - "[ -d /var/cache/gitlab-runner ] || sudo mkdir /var/cache/gitlab-runner"
+ - sudo chown cirunner:cirunner -R /var/cache/gitlab-runner
+ - bundle install --jobs $(nproc) --without system_tests --path=/var/cache/gitlab-runner/ "${FLAGS[@]}"
-# don't fail on lint warnings
-rspec:
+.job_template: &job_definition
script:
+ # don't fail on lint warnings
- bundle exec rake lint || /bin/true
- bundle exec rake syntax
- bundle exec rake validate
- bundle exec rake spec
+
+# Default debian jessie versions
+test:puppet37:
+ variables:
+ PUPPET_VERSION: "~> 3.7.2"
+ FACTER_VERSION: '~> 2.2.0'
+ <<: *job_definition
+
+test:puppet38_future_parser:
+ variables:
+ PUPPET_VERSION: '~> 3.8'
+ FACTER_VERSION: '~> 2.2.0'
+ FUTURE_PARSER: 'yes'
+ <<: *job_definition
+
+# Default debia stretch versions
+test:puppet45:
+ variables:
+ PUPPET_VERSION: "~> 4.5.2"
+ FACTER_VERSION: '~> 2.4.6'
+ <<: *job_definition
+
+# Latest greatest
+test:puppet4x:
+ variables:
+ PUPPET_VERSION: "> 4"
+ FACTER_VERSION: '> 2'
+ <<: *job_definition
+
diff --git a/Gemfile b/Gemfile
index 7ef1ec3..226d7ae 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,8 +2,8 @@ source "https://rubygems.org"
group :development, :unit_tests do
gem "rake"
- gem "rspec", '< 3.2.0'
- gem "rspec-puppet"
+ gem "rspec-puppet", "~> 2.1", :require => false
+ gem "rspec-core"
gem "puppetlabs_spec_helper"
gem "metadata-json-lint"
gem "rspec-puppet-facts"
diff --git a/manifests/apt_conf.pp b/manifests/apt_conf.pp
index 949f615..8225915 100644
--- a/manifests/apt_conf.pp
+++ b/manifests/apt_conf.pp
@@ -1,15 +1,15 @@
-define apt::apt_conf(
- $ensure = 'present',
- $source = '',
- $content = undef,
- $refresh_apt = true )
-{
+define apt::apt_conf (
+ $ensure = 'present',
+ $source = undef,
+ $content = undef,
+ $refresh_apt = true,
+) {
- if $source == '' and $content == undef {
+ if $source == undef and $content == undef {
fail("One of \$source or \$content must be specified for apt_conf ${name}")
}
- if $source != '' and $content != undef {
+ if $source != undef and $content != undef {
fail("Only one of \$source or \$content must specified for apt_conf ${name}")
}
@@ -38,8 +38,7 @@ define apt::apt_conf(
if $refresh_apt {
File["/etc/apt/apt.conf.d/${name}"] {
- notify => Exec['apt_updated'],
+ notify => Exec['update_apt'],
}
}
-
}
diff --git a/manifests/apticron.pp b/manifests/apticron.pp
index 89709a8..0adcc68 100644
--- a/manifests/apticron.pp
+++ b/manifests/apticron.pp
@@ -1,18 +1,20 @@
-class apt::apticron(
- $ensure_version = 'installed',
- $config = "apt/${::operatingsystem}/apticron.erb",
- $email = 'root',
- $diff_only = '1',
+class apt::apticron (
+ $ensure_version = 'present',
+ $config = "apt/${::operatingsystem}/apticron.erb",
+ $email = 'root',
+ $diff_only = '1',
$listchanges_profile = 'apticron',
- $system = false,
- $ipaddressnum = false,
- $ipaddresses = false,
- $notifyholds = '0',
- $notifynew = '0',
- $customsubject = ''
+ $system = false,
+ $ipaddressnum = false,
+ $ipaddresses = false,
+ $notifyholds = '0',
+ $notifynew = '0',
+ $customsubject = '',
) {
- package { 'apticron': ensure => $ensure_version }
+ package { 'apticron':
+ ensure => $ensure_version;
+ }
file { '/etc/apticron/apticron.conf':
content => template($apt::apticron::config),
diff --git a/manifests/config.pp b/manifests/config.pp
new file mode 100644
index 0000000..542fc1f
--- /dev/null
+++ b/manifests/config.pp
@@ -0,0 +1,89 @@
+class apt::config {
+
+ exec { 'update_apt':
+ command => '/usr/bin/apt-get update',
+ require => [ File['/etc/apt/apt.conf.d',
+ '/etc/apt/preferences',
+ '/etc/apt/sources.list'] ],
+ refreshonly => true;
+ }
+
+ $sources_content = $apt::custom_sources_list ? {
+ '' => template( "apt/${::operatingsystem}/sources.list.erb"),
+ default => $apt::custom_sources_list,
+ }
+ file {
+ # include main and security
+ # additional sources should be included via the apt::sources_list define
+ '/etc/apt/sources.list':
+ content => $sources_content,
+ notify => Exec['update_apt'],
+ owner => root,
+ group => 0,
+ mode => '0644';
+ }
+
+ # workaround for preseeded_package component
+ file {
+ [ '/var/cache',
+ '/var/cache/local',
+ '/var/cache/local/preseeding' ]:
+ ensure => directory;
+ }
+
+ ::apt::apt_conf { '02show_upgraded':
+ source => [ "puppet:///modules/site_apt/${::fqdn}/02show_upgraded",
+ 'puppet:///modules/site_apt/02show_upgraded',
+ 'puppet:///modules/apt/02show_upgraded' ];
+ }
+
+ if ( $::virtual == 'vserver' ) {
+ ::apt::apt_conf { '03clean_vserver':
+ source => [ "puppet:///modules/site_apt/${::fqdn}/03clean_vserver",
+ 'puppet:///modules/site_apt/03clean_vserver',
+ 'puppet:///modules/apt/03clean_vserver' ],
+ alias => '03clean';
+ }
+ }
+ else {
+ ::apt::apt_conf { '03clean':
+ source => [ "puppet:///modules/site_apt/${::fqdn}/03clean",
+ 'puppet:///modules/site_apt/03clean',
+ 'puppet:///modules/apt/03clean' ];
+ }
+ }
+
+ if ($apt::use_backports and !($::debian_release in ['testing', 'unstable', 'experimental'])) {
+ apt::sources_list {
+ 'backports':
+ content => "deb ${apt::debian_url} ${::debian_codename}-backports ${apt::repos}",
+ }
+ if $apt::include_src {
+ apt::sources_list {
+ 'backports-src':
+ content => "deb-src ${apt::debian_url} ${::debian_codename}-backports ${apt::repos}",
+ }
+ }
+ }
+
+ if $apt::custom_key_dir {
+ file { "${apt::apt_base_dir}/keys.d":
+ source => $apt::custom_key_dir,
+ recurse => true,
+ owner => root,
+ group => root,
+ mode => '0755',
+ }
+ exec { 'custom_keys':
+ command => "find ${apt::apt_base_dir}/keys.d -type f -exec apt-key add '{}' \\;",
+ subscribe => File["${apt::apt_base_dir}/keys.d"],
+ refreshonly => true,
+ notify => Exec['update_apt'];
+ }
+ if $apt::custom_preferences != false {
+ Exec['custom_keys'] {
+ before => File['apt_config'],
+ }
+ }
+ }
+}
diff --git a/manifests/cron/dist_upgrade.pp b/manifests/cron/dist_upgrade.pp
index e1a03ed..db36544 100644
--- a/manifests/cron/dist_upgrade.pp
+++ b/manifests/cron/dist_upgrade.pp
@@ -2,7 +2,9 @@ class apt::cron::dist_upgrade (
$cron_hours = '',
) {
- package { 'cron-apt': ensure => installed }
+ package { 'cron-apt':
+ ensure => present;
+ }
case $cron_hours {
'': {}
@@ -12,7 +14,7 @@ class apt::cron::dist_upgrade (
cron { 'apt_cron_every_N_hours':
command => 'test -x /usr/sbin/cron-apt && /usr/sbin/cron-apt',
user => root,
- hour => "${cron_hours}",
+ hour => $cron_hours,
minute => 10,
require => Package['cron-apt'],
}
@@ -27,14 +29,16 @@ dist-upgrade -y -o APT::Get::Show-Upgraded=true -o 'DPkg::Options::=--force-conf
ensure => absent,
}
- package { 'apt-listbugs': ensure => absent }
+ package { 'apt-listbugs':
+ ensure => absent;
+ }
file { '/etc/cron-apt/action.d/4-dist-upgrade':
content => $action,
owner => root,
group => 0,
mode => '0644',
- require => Package[cron-apt];
+ require => Package['cron-apt'];
}
file { '/etc/cron-apt/config.d/MAILON':
@@ -42,7 +46,6 @@ dist-upgrade -y -o APT::Get::Show-Upgraded=true -o 'DPkg::Options::=--force-conf
owner => root,
group => 0,
mode => '0644',
- require => Package[cron-apt];
+ require => Package['cron-apt'];
}
-
}
diff --git a/manifests/dist_upgrade.pp b/manifests/dist_upgrade.pp
index 3061fb8..eb3207c 100644
--- a/manifests/dist_upgrade.pp
+++ b/manifests/dist_upgrade.pp
@@ -6,7 +6,6 @@ class apt::dist_upgrade (
command => '/usr/bin/apt-get -q -y -o \'DPkg::Options::=--force-confold\' dist-upgrade',
refreshonly => true,
timeout => $timeout,
- before => Exec['apt_updated']
+ before => Exec['update_apt'];
}
-
}
diff --git a/manifests/dist_upgrade/initiator.pp b/manifests/dist_upgrade/initiator.pp
index d238988..5dfce14 100644
--- a/manifests/dist_upgrade/initiator.pp
+++ b/manifests/dist_upgrade/initiator.pp
@@ -1,6 +1,6 @@
class apt::dist_upgrade::initiator inherits apt::dist_upgrade {
- $initiator = 'upgrade_initiator'
+ $initiator = 'upgrade_initiator'
$initiator_abs = "${apt::apt_base_dir}/${initiator}"
file { 'apt_upgrade_initiator':
@@ -9,15 +9,12 @@ class apt::dist_upgrade::initiator inherits apt::dist_upgrade {
group => 0,
path => $initiator_abs,
checksum => md5,
- source => [
- "puppet:///modules/site_apt/${::fqdn}/${initiator}",
+ source => [ "puppet:///modules/site_apt/${::fqdn}/${initiator}",
"puppet:///modules/site_apt/${initiator}",
- "puppet:///modules/apt/${initiator}",
- ],
+ "puppet:///modules/apt/${initiator}" ],
}
Exec['apt_dist-upgrade'] {
subscribe +> File['apt_upgrade_initiator'],
}
-
}
diff --git a/manifests/dot_d_directories.pp b/manifests/dot_d_directories.pp
index 0ace863..6d9f790 100644
--- a/manifests/dot_d_directories.pp
+++ b/manifests/dot_d_directories.pp
@@ -1,15 +1,16 @@
+# watch .d directories and ensure they are present
+
class apt::dot_d_directories {
- # watch .d directories and ensure they are present
file {
'/etc/apt/apt.conf.d':
ensure => directory,
checksum => mtime,
- notify => Exec['apt_updated'];
+ notify => Exec['update_apt'];
+
'/etc/apt/sources.list.d':
ensure => directory,
checksum => mtime,
- notify => Exec['apt_updated'];
+ notify => Exec['update_apt'];
}
-
}
diff --git a/manifests/dselect.pp b/manifests/dselect.pp
index 2b99a43..bfc6cb3 100644
--- a/manifests/dselect.pp
+++ b/manifests/dselect.pp
@@ -1,5 +1,6 @@
# manage dselect, like
# suppressing the annoying help texts
+
class apt::dselect {
file_line { 'dselect_expert':
@@ -7,5 +8,7 @@ class apt::dselect {
line => 'expert',
}
- package { 'dselect': ensure => installed }
+ package { 'dselect':
+ ensure => present;
+ }
}
diff --git a/manifests/init.pp b/manifests/init.pp
index 4bf126c..26afaeb 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -3,64 +3,30 @@
# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
# See LICENSE for the full license granted to you.
-class apt(
- $use_lts = $apt::params::use_lts,
- $use_volatile = $apt::params::use_volatile,
- $use_backports = $apt::params::use_backports,
- $include_src = $apt::params::include_src,
- $use_next_release = $apt::params::use_next_release,
- $debian_url = $apt::params::debian_url,
- $security_url = $apt::params::security_url,
- $lts_url = $apt::params::lts_url,
- $volatile_url = $apt::params::volatile_url,
- $ubuntu_url = $apt::params::ubuntu_url,
- $repos = $apt::params::repos,
- $custom_preferences = $apt::params::custom_preferences,
+class apt (
+ $use_lts = $apt::params::use_lts,
+ $use_volatile = $apt::params::use_volatile,
+ $use_backports = $apt::params::use_backports,
+ $include_src = $apt::params::include_src,
+ $use_next_release = $apt::params::use_next_release,
+ $debian_url = $apt::params::debian_url,
+ $security_url = $apt::params::security_url,
+ $lts_url = $apt::params::lts_url,
+ $volatile_url = $apt::params::volatile_url,
+ $ubuntu_url = $apt::params::ubuntu_url,
+ $repos = $apt::params::repos,
+ $custom_preferences = $apt::params::custom_preferences,
$custom_sources_list = '',
- $custom_key_dir = $apt::params::custom_key_dir
+ $custom_key_dir = $apt::params::custom_key_dir,
) inherits apt::params {
- package { 'apt':
- ensure => installed,
- require => undef,
- }
-
- $sources_content = $custom_sources_list ? {
- '' => template( "apt/${::operatingsystem}/sources.list.erb"),
- default => $custom_sources_list
- }
- file {
- # include main and security
- # additional sources should be included via the apt::sources_list define
- '/etc/apt/sources.list':
- content => $sources_content,
- notify => Exec['apt_updated'],
- owner => root,
- group => 0,
- mode => '0644';
- }
-
- apt_conf { '02show_upgraded':
- source => [ "puppet:///modules/site_apt/${::fqdn}/02show_upgraded",
- 'puppet:///modules/site_apt/02show_upgraded',
- 'puppet:///modules/apt/02show_upgraded' ]
- }
+ include apt::dot_d_directories
+ include apt::config
+ include apt::install
- if ( $::virtual == 'vserver' ) {
- apt_conf { '03clean_vserver':
- source => [ "puppet:///modules/site_apt/${::fqdn}/03clean_vserver",
- 'puppet:///modules/site_apt/03clean_vserver',
- 'puppet:///modules/apt/03clean_vserver' ],
- alias => '03clean';
- }
- }
- else {
- apt_conf { '03clean':
- source => [ "puppet:///modules/site_apt/${::fqdn}/03clean",
- 'puppet:///modules/site_apt/03clean',
- 'puppet:///modules/apt/03clean' ]
- }
- }
+ include common::moduledir
+ common::module_dir { 'apt': }
+ $apt_base_dir = "${common::moduledir::module_dir_path}/apt"
case $custom_preferences {
false: {
@@ -70,61 +36,4 @@ class apt(
include apt::preferences
}
}
-
- include apt::dot_d_directories
-
- ## This package should really always be current
- package { 'debian-archive-keyring': ensure => latest }
-
- if ($use_backports and !($::debian_release in ['testing', 'unstable', 'experimental'])) {
- apt::sources_list {
- 'backports':
- content => "deb ${debian_url} ${::debian_codename}-backports ${apt::repos}",
- }
- if $include_src {
- apt::sources_list {
- 'backports-src':
- content => "deb-src ${debian_url} ${::debian_codename}-backports ${apt::repos}",
- }
- }
- }
-
- include common::moduledir
- common::module_dir { 'apt': }
- $apt_base_dir = "${common::moduledir::module_dir_path}/apt"
-
- if $custom_key_dir {
- file { "${apt_base_dir}/keys.d":
- source => $custom_key_dir,
- recurse => true,
- owner => root,
- group => root,
- mode => '0755',
- }
- exec { 'custom_keys':
- command => "find ${apt_base_dir}/keys.d -type f -exec apt-key add '{}' \\;",
- subscribe => File["${apt_base_dir}/keys.d"],
- refreshonly => true,
- notify => Exec[refresh_apt]
- }
- if $custom_preferences != false {
- Exec['custom_keys'] {
- before => File['apt_config']
- }
- }
- }
-
- # workaround for preseeded_package component
- file { [ '/var/cache', '/var/cache/local', '/var/cache/local/preseeding' ]: ensure => directory }
-
- exec { 'update_apt':
- command => '/usr/bin/apt-get update',
- require => [
- File['/etc/apt/apt.conf.d', '/etc/apt/preferences' ],
- File['/etc/apt/sources.list'] ],
- refreshonly => true,
- # Another Semaphor for all packages to reference
- alias => [ 'apt_updated', 'refresh_apt']
- }
-
}
diff --git a/manifests/install.pp b/manifests/install.pp
new file mode 100644
index 0000000..76eb570
--- /dev/null
+++ b/manifests/install.pp
@@ -0,0 +1,11 @@
+class apt::install {
+
+ package { 'apt':
+ ensure => present;
+ }
+
+ # This package should really always be current
+ package { 'debian-archive-keyring':
+ ensure => latest;
+ }
+}
diff --git a/manifests/key.pp b/manifests/key.pp
index cb70ec6..6ec6523 100644
--- a/manifests/key.pp
+++ b/manifests/key.pp
@@ -8,6 +8,6 @@ define apt::key ($source, $ensure = 'present') {
"/etc/apt/trusted.gpg.d/${name}":
ensure => $ensure,
source => $source,
- notify => Exec['apt_updated'],
+ notify => Exec['update_apt'],
}
}
diff --git a/manifests/key/plain.pp b/manifests/key/plain.pp
index dff8b51..e845b88 100644
--- a/manifests/key/plain.pp
+++ b/manifests/key/plain.pp
@@ -8,6 +8,6 @@ define apt::key::plain ($source) {
exec { "apt-key add '${apt::apt_base_dir}/keys/${name}'":
subscribe => File["${apt::apt_base_dir}/keys/${name}"],
refreshonly => true,
- notify => Exec['apt_updated'],
+ notify => Exec['update_apt'],
}
}
diff --git a/manifests/listchanges.pp b/manifests/listchanges.pp
index ecbbe6d..d657812 100644
--- a/manifests/listchanges.pp
+++ b/manifests/listchanges.pp
@@ -1,13 +1,16 @@
-class apt::listchanges(
- $ensure_version = 'installed',
- $config = "apt/${::operatingsystem}/listchanges.erb",
- $frontend = 'mail',
- $email = 'root',
- $confirm = '0',
- $saveseen = '/var/lib/apt/listchanges.db',
- $which = 'both'
+class apt::listchanges (
+ $ensure_version = 'present',
+ $config = "apt/${::operatingsystem}/listchanges.erb",
+ $frontend = 'mail',
+ $email = 'root',
+ $confirm = '0',
+ $saveseen = '/var/lib/apt/listchanges.db',
+ $which = 'both',
){
- package { 'apt-listchanges': ensure => $ensure_version }
+
+ package { 'apt-listchanges':
+ ensure => $ensure_version;
+ }
file { '/etc/apt/listchanges.conf':
content => template($apt::listchanges::config),
diff --git a/manifests/params.pp b/manifests/params.pp
index 2b18eb5..463cd63 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -1,14 +1,14 @@
class apt::params () {
- $use_lts = false
- $use_volatile = false
- $use_backports = true
- $include_src = false
+ $use_lts = false
+ $use_volatile = false
+ $use_backports = true
+ $include_src = false
$use_next_release = false
- $debian_url = 'http://httpredir.debian.org/debian/'
- $security_url = 'http://security.debian.org/'
- $ubuntu_url = 'http://archive.ubuntu.com/ubuntu'
- $lts_url = $debian_url
- $volatile_url = 'http://volatile.debian.org/debian-volatile/'
+ $debian_url = 'http://httpredir.debian.org/debian/'
+ $security_url = 'http://security.debian.org/'
+ $ubuntu_url = 'http://archive.ubuntu.com/ubuntu'
+ $lts_url = $debian_url
+ $volatile_url = 'http://volatile.debian.org/debian-volatile/'
case $::operatingsystem {
'debian': {
$repos = 'main contrib non-free'
diff --git a/manifests/preferences.pp b/manifests/preferences.pp
index aedd56b..d3eb780 100644
--- a/manifests/preferences.pp
+++ b/manifests/preferences.pp
@@ -16,5 +16,4 @@ class apt::preferences {
require => File['/etc/apt/sources.list'],
owner => root, group => 0, mode => '0644';
}
-
}
diff --git a/manifests/preferences_snippet.pp b/manifests/preferences_snippet.pp
index b7dba0d..8905318 100644
--- a/manifests/preferences_snippet.pp
+++ b/manifests/preferences_snippet.pp
@@ -1,10 +1,10 @@
define apt::preferences_snippet (
$priority = undef,
- $package = false,
- $ensure = 'present',
- $source = '',
- $release = '',
- $pin = ''
+ $package = false,
+ $ensure = 'present',
+ $source = undef,
+ $release = undef,
+ $pin = undef,
) {
$real_package = $package ? {
@@ -18,41 +18,41 @@ define apt::preferences_snippet (
}
if $priority == undef {
- fail('apt::preferences_snippet requires the \'priority\' argument to be set')
+ fail("apt::preferences_snippet requires the 'priority' argument to be set")
}
if !$pin and !$release {
- fail('apt::preferences_snippet requires one of the \'pin\' or \'release\' argument to be set')
+ fail("apt::preferences_snippet requires one of the 'pin' or 'release' argument to be set")
}
if $pin and $release {
- fail('apt::preferences_snippet requires either a \'pin\' or \'release\' argument, not both')
+ fail("apt::preferences_snippet requires either a 'pin' or 'release' argument, not both")
}
}
file { "/etc/apt/preferences.d/${name}":
ensure => $ensure,
owner => root, group => 0, mode => '0644',
- before => Exec['apt_updated'];
+ before => Exec['update_apt'];
}
case $source {
- '': {
+ undef: {
case $release {
- '': {
+ undef: {
File["/etc/apt/preferences.d/${name}"]{
- content => template('apt/preferences_snippet.erb')
+ content => template('apt/preferences_snippet.erb'),
}
}
default: {
File["/etc/apt/preferences.d/${name}"]{
- content => template('apt/preferences_snippet_release.erb')
+ content => template('apt/preferences_snippet_release.erb'),
}
}
}
}
default: {
File["/etc/apt/preferences.d/${name}"]{
- source => $source
+ source => $source,
}
}
}
diff --git a/manifests/preseeded_package.pp b/manifests/preseeded_package.pp
index 162ade7..29a981e 100644
--- a/manifests/preseeded_package.pp
+++ b/manifests/preseeded_package.pp
@@ -1,12 +1,14 @@
# Install a package with a preseed file to automatically answer some questions.
+
define apt::preseeded_package (
- $ensure = 'installed',
- $content = ''
+ $ensure = 'present',
+ $content = '',
) {
+
$seedfile = "/var/cache/local/preseeding/${name}.seeds"
$real_content = $content ? {
'' => template ( "site_apt/${::debian_codename}/${name}.seeds" ),
- default => $content
+ default => $content,
}
file { $seedfile:
diff --git a/manifests/proxy_client.pp b/manifests/proxy_client.pp
index 9ba79f2..0793878 100644
--- a/manifests/proxy_client.pp
+++ b/manifests/proxy_client.pp
@@ -1,9 +1,9 @@
-class apt::proxy_client(
+class apt::proxy_client (
$proxy = 'http://localhost',
- $port = '3142',
-){
+ $port = '3142',
+) {
- apt_conf { '20proxy':
+ ::apt::apt_conf { '20proxy':
content => template('apt/20proxy.erb'),
}
}
diff --git a/manifests/reboot_required_notify.pp b/manifests/reboot_required_notify.pp
index efd8aeb..3463bb4 100644
--- a/manifests/reboot_required_notify.pp
+++ b/manifests/reboot_required_notify.pp
@@ -7,5 +7,4 @@ class apt::reboot_required_notify {
} else {
class { 'apt::reboot_required_notify::wheezy': }
}
-
}
diff --git a/manifests/reboot_required_notify/jessie.pp b/manifests/reboot_required_notify/jessie.pp
index 2de6b62..fcd3fb3 100644
--- a/manifests/reboot_required_notify/jessie.pp
+++ b/manifests/reboot_required_notify/jessie.pp
@@ -1,5 +1,7 @@
class apt::reboot_required_notify::jessie ($ensure = present) {
+ include apt
+
if $::operatingsystemmajrelease == 8 and ! $::apt::use_backports {
fail('apt::reboot_required_notify requires $apt::use_backports on Jessie')
}
@@ -24,5 +26,4 @@ class apt::reboot_required_notify::jessie ($ensure = present) {
ensure => $ensure,
require => Apt::Preferences_snippet['reboot-notifier'],
}
-
}
diff --git a/manifests/reboot_required_notify/wheezy.pp b/manifests/reboot_required_notify/wheezy.pp
index 06998ef..1ad46cd 100644
--- a/manifests/reboot_required_notify/wheezy.pp
+++ b/manifests/reboot_required_notify/wheezy.pp
@@ -19,5 +19,4 @@ class apt::reboot_required_notify::wheezy ($ensure = present) {
minute => 20,
require => Package['update-notifier-common'],
}
-
}
diff --git a/manifests/sources_list.pp b/manifests/sources_list.pp
index 7565bce..35a7643 100644
--- a/manifests/sources_list.pp
+++ b/manifests/sources_list.pp
@@ -1,15 +1,16 @@
# Configure an apt source
+
define apt::sources_list (
- $ensure = 'present',
- $source = '',
- $content = undef
+ $ensure = 'present',
+ $source = undef,
+ $content = undef,
) {
if $ensure == 'present' {
- if $source == '' and $content == undef {
+ if $source == undef and $content == undef {
fail("One of \$source or \$content must be specified for apt_sources_snippet ${name}")
}
- if $source != '' and $content != undef {
+ if $source != undef and $content != undef {
fail("Only one of \$source or \$content must specified for apt_sources_snippet ${name}")
}
}
@@ -26,7 +27,7 @@ define apt::sources_list (
mode => '0644',
owner => 'root',
group => 0,
- notify => Exec['apt_updated'],
+ notify => Exec['update_apt'],
}
if $source {
diff --git a/manifests/unattended_upgrades.pp b/manifests/unattended_upgrades.pp
index 52d7542..c6db396 100644
--- a/manifests/unattended_upgrades.pp
+++ b/manifests/unattended_upgrades.pp
@@ -1,14 +1,14 @@
class apt::unattended_upgrades (
- $config_content = undef,
- $config_template = 'apt/50unattended-upgrades.erb',
- $mailonlyonerror = true,
- $mail_recipient = 'root',
+ $config_content = undef,
+ $config_template = 'apt/50unattended-upgrades.erb',
+ $mailonlyonerror = true,
+ $mail_recipient = 'root',
$blacklisted_packages = [],
- $ensure_version = present
+ $ensure_version = 'present',
) {
package { 'unattended-upgrades':
- ensure => $ensure_version
+ ensure => $ensure_version,
}
# For some reason, this directory is sometimes absent, which causes
@@ -23,12 +23,12 @@ class apt::unattended_upgrades (
$file_content = $config_content ? {
undef => template($config_template),
- default => $config_content
+ default => $config_content,
}
- apt_conf { '50unattended-upgrades':
+ ::apt::apt_conf { '50unattended-upgrades':
content => $file_content,
require => Package['unattended-upgrades'],
- refresh_apt => false
+ refresh_apt => false;
}
}
diff --git a/manifests/update.pp b/manifests/update.pp
index dde8320..72cedc2 100644
--- a/manifests/update.pp
+++ b/manifests/update.pp
@@ -1,7 +1,6 @@
class apt::update inherits ::apt {
Exec['update_apt'] {
- refreshonly => false
+ refreshonly => false,
}
-
}
diff --git a/manifests/upgrade_package.pp b/manifests/upgrade_package.pp
index e61b15d..3ba2077 100644
--- a/manifests/upgrade_package.pp
+++ b/manifests/upgrade_package.pp
@@ -1,7 +1,8 @@
# Install a package either to a certain version, or while making sure that it's
# always the latest version that's installed.
+
define apt::upgrade_package (
- $version = ''
+ $version = '',
) {
$version_suffix = $version ? {
@@ -12,22 +13,19 @@ define apt::upgrade_package (
if !defined(Package['apt-show-versions']) {
package { 'apt-show-versions':
- ensure => installed,
- require => undef,
+ ensure => present,
}
}
if !defined(Package['dctrl-tools']) {
package { 'dctrl-tools':
- ensure => installed,
- require => undef,
+ ensure => present,
}
}
exec { "apt-get -q -y -o 'DPkg::Options::=--force-confold' install ${name}${version_suffix}":
onlyif => [ "grep-status -F Status installed -a -P ${name} -q", "apt-show-versions -u ${name} | grep -q upgradeable" ],
require => Package['apt-show-versions', 'dctrl-tools'],
- before => Exec['apt_updated']
+ before => Exec['update_apt'];
}
-
}
diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb
new file mode 100644
index 0000000..9ba554f
--- /dev/null
+++ b/spec/classes/init_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe 'apt', :type => :class do
+ let :pre_condition do
+ 'class { "apt": }'
+ end
+ let(:facts) { {
+ :lsbdistid => 'Debian',
+ :osfamily => 'Debian',
+ :operatingsystem => 'Debian',
+ :debian_release => 'jessie',
+ :debian_codename => 'jessie',
+ :lsbdistcodename => 'jessie',
+ :virtual => 'physical',
+ :puppetversion => Puppet.version, } }
+ #it { is_expected.to compile.with_all_deps }
+ it { is_expected.to compile }
+end
diff --git a/spec/defines/conf_spec.rb b/spec/defines/conf_spec.rb
new file mode 100644
index 0000000..cc4fb1f
--- /dev/null
+++ b/spec/defines/conf_spec.rb
@@ -0,0 +1,74 @@
+require 'spec_helper'
+describe 'apt::apt_conf', :type => :define do
+ let :pre_condition do
+ 'class { "apt": }'
+ end
+ let(:facts) { {
+ :lsbdistid => 'Debian',
+ :osfamily => 'Debian',
+ :operatingsystem => 'Debian',
+ :debian_release => 'jessie',
+ :debian_codename => 'jessie',
+ :lsbdistcodename => 'jessie',
+ :virtual => 'physical',
+ :puppetversion => Puppet.version, } }
+ let :title do
+ 'norecommends'
+ end
+
+ describe "when creating an apt_conf snippet" do
+ let :default_params do
+ {
+ :ensure => 'present',
+ :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
+ }
+ end
+ let :params do
+ default_params
+ end
+ let :filename do
+ "/etc/apt/apt.conf.d/norecommends"
+ end
+
+ it { is_expected.to contain_file(filename).with({
+ 'ensure' => 'present',
+ 'content' => /Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;/,
+ 'owner' => 'root',
+ # default to '0', not 'root'
+ #'group' => 'root',
+ 'mode' => '0644',
+ })
+ }
+
+ end
+
+ describe "when creating a preference without content" do
+ let :params do
+ {
+ :ensure => 'absent',
+ }
+ end
+
+ it 'fails' do
+ expect { subject.call } .to raise_error(Puppet::Error, /One of \$source or \$content must be specified for apt_conf norecommends/)
+ end
+ end
+
+ describe "when removing an apt preference" do
+ let :params do
+ {
+ :ensure => 'absent',
+ :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
+ }
+ end
+
+ let :filename do
+ "/etc/apt/apt.conf.d/norecommends"
+ end
+
+ it { is_expected.to contain_file(filename).with({
+ 'ensure' => 'absent',
+ })
+ }
+ end
+end
diff --git a/spec/defines/preferences_snippet_spec.rb b/spec/defines/preferences_snippet_spec.rb
new file mode 100644
index 0000000..012a5f6
--- /dev/null
+++ b/spec/defines/preferences_snippet_spec.rb
@@ -0,0 +1,66 @@
+require 'spec_helper'
+describe 'apt::preferences_snippet', :type => :define do
+ let :pre_condition do
+ 'class { "apt": }'
+ end
+ let(:facts) { {
+ :lsbdistid => 'Debian',
+ :osfamily => 'Debian',
+ :operatingsystem => 'Debian',
+ :debian_release => 'jessie',
+ :debian_codename => 'jessie',
+ :lsbdistcodename => 'jessie',
+ :virtual => 'physical',
+ :puppetversion => Puppet.version, } }
+ let :title do
+ 'test'
+ end
+
+ describe "when creating a preferences_snippet" do
+ let :default_params do
+ {
+ :ensure => 'present',
+ :release => "jessie-backports",
+ :priority => '999'
+ }
+ end
+ let :params do
+ default_params
+ end
+ let :filename do
+ "/etc/apt/preferences.d/test"
+ end
+
+ it { is_expected.to contain_file(filename).with({
+ 'ensure' => 'present',
+ 'content' => /Package: test\nPin: release a=jessie-backports\nPin-Priority: 999/,
+ 'owner' => 'root',
+ 'group' => '0',
+ 'mode' => '0644',
+ })
+ }
+
+ end
+
+ describe "when using both pin and release parameters" do
+ let :default_params do
+ {
+ :ensure => 'present',
+ :priority => '999',
+ :release => "jessie-backports",
+ :pin => '1.0'
+ }
+ end
+ let :params do
+ default_params
+ end
+ let :filename do
+ "/etc/apt/preferences.d/test"
+ end
+
+ it 'fails' do
+ expect { subject.call } .to raise_error(Puppet::Error, /apt::preferences_snippet requires either a 'pin' or 'release' argument, not both/)
+ end
+ end
+
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 21d1a98..3cca63a 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,12 +1,12 @@
# https://puppetlabs.com/blog/testing-modules-in-the-puppet-forge
-require 'rspec-puppet'
-require 'mocha/api'
+require 'puppetlabs_spec_helper/module_spec_helper'
-RSpec.configure do |c|
+fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
- c.module_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
- c.color = true
+RSpec.configure do |c|
- #Puppet.features.stubs(:root? => true)
+ c.manifest_dir = File.join(fixture_path, 'manifests')
+ c.module_path = File.join(fixture_path, 'modules')
+ c.color = true
end