From 3f0a363088c64c905a3fe7f6369d28b770cdf481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis-Philippe=20V=C3=A9ronneau?= Date: Fri, 24 Feb 2017 16:30:49 -0500 Subject: fix custom_preferences && refactor how they work --- manifests/init.pp | 9 +--- manifests/params.pp | 23 +++++----- manifests/preferences.pp | 93 ++++++++++++++++++++++++++-------------- manifests/preferences/absent.pp | 7 --- manifests/preferences_snippet.pp | 3 -- 5 files changed, 73 insertions(+), 62 deletions(-) delete mode 100644 manifests/preferences/absent.pp diff --git a/manifests/init.pp b/manifests/init.pp index 26afaeb..3a37f6b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -23,17 +23,10 @@ class apt ( include apt::dot_d_directories include apt::config include apt::install + include apt::preferences include common::moduledir common::module_dir { 'apt': } $apt_base_dir = "${common::moduledir::module_dir_path}/apt" - case $custom_preferences { - false: { - include apt::preferences::absent - } - default: { - include apt::preferences - } - } } diff --git a/manifests/params.pp b/manifests/params.pp index 463cd63..3879c81 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,14 +1,16 @@ class apt::params () { - $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/' + $use_lts = false + $use_volatile = false + $use_backports = true + $include_src = false + $use_next_release = false + $manage_preferences = true + $custom_preferences = undef + $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' @@ -20,6 +22,5 @@ class apt::params () { fail("Unsupported system '${::operatingsystem}'.") } } - $custom_preferences = '' $custom_key_dir = false } diff --git a/manifests/preferences.pp b/manifests/preferences.pp index 787f46f..548098f 100644 --- a/manifests/preferences.pp +++ b/manifests/preferences.pp @@ -1,56 +1,83 @@ class apt::preferences { - if $::operatingsystem == "Debian" { - - file { '/etc/apt/preferences.d/stable': - ensure => present, - alias => 'apt_config', - # only update together - content => template('apt/Debian/stable.erb'), - require => File['/etc/apt/sources.list'], - owner => root, group => 0, mode => '0644'; + if ($apt::manage_preferences == true) and ($apt::custom_preferences != undef) { + + file { '/etc/apt/preferences.d/custom': + ensure => present, + alias => 'apt_config', + # only update together + content => $custom_preferences, + require => File['/etc/apt/sources.list'], + owner => root, group => 0, mode => '0644'; } + } - if $apt::use_volatile { + elsif $apt::manage_preferences == true { - file { '/etc/apt/preferences.d/volatile': + if $::operatingsystem == "Debian" { + + file { '/etc/apt/preferences.d/stable': ensure => present, - content => template('apt/Debian/volatile.erb'), + alias => 'apt_config', + # only update together + content => template('apt/Debian/stable.erb'), require => File['/etc/apt/sources.list'], owner => root, group => 0, mode => '0644'; } - } - if $apt::use_lts { + if $apt::use_volatile { - file { '/etc/apt/preferences.d/lts': - ensure => present, - content => template('apt/Debian/lts.erb'), - require => File['/etc/apt/sources.list'], - owner => root, group => 0, mode => '0644'; + file { '/etc/apt/preferences.d/volatile': + ensure => present, + content => template('apt/Debian/volatile.erb'), + require => File['/etc/apt/sources.list'], + owner => root, group => 0, mode => '0644'; + } + } + + if $apt::use_lts { + + file { '/etc/apt/preferences.d/lts': + ensure => present, + content => template('apt/Debian/lts.erb'), + require => File['/etc/apt/sources.list'], + owner => root, group => 0, mode => '0644'; + } + } + + if ($::debian_nextcodename) and ($::debian_nextcodename != "experimental") { + + file { '/etc/apt/preferences.d/nextcodename': + ensure => present, + content => template('apt/Debian/nextcodename.erb'), + require => File['/etc/apt/sources.list'], + owner => root, group => 0, mode => '0644'; + } } } - if ($::debian_nextcodename) and ($::debian_nextcodename != "experimental") { + elsif $::operatingsystem == "Ubuntu" { - file { '/etc/apt/preferences.d/nextcodename': - ensure => present, - content => template('apt/Debian/nextcodename.erb'), - require => File['/etc/apt/sources.list'], - owner => root, group => 0, mode => '0644'; + file { '/etc/apt/preferences': + ensure => present, + alias => 'apt_config', + # only update together + content => template("apt/Ubuntu/preferences_${apt::codename}.erb"), + require => File['/etc/apt/sources.list'], + owner => root, group => 0, mode => '0644'; } } } - elsif $::operatingsystem == "Ubuntu" { + elsif $apt::manage_preferences == false { - file { '/etc/apt/preferences': - ensure => present, - alias => 'apt_config', - # only update together - content => template("apt/Ubuntu/preferences_${apt::codename}.erb"), - require => File['/etc/apt/sources.list'], - owner => root, group => 0, mode => '0644'; + file { + [ '/etc/apt/preferences.d/custom', + '/etc/apt/preferences.d/stable', + '/etc/apt/preferences.d/volatile', + '/etc/apt/preferences.d/lts', + '/etc/apt/preferences.d/nextcodename']: + ensure => absent; } } } diff --git a/manifests/preferences/absent.pp b/manifests/preferences/absent.pp deleted file mode 100644 index f32e030..0000000 --- a/manifests/preferences/absent.pp +++ /dev/null @@ -1,7 +0,0 @@ -class apt::preferences::absent { - - file { '/etc/apt/preferences': - ensure => absent, - alias => 'apt_config', - } -} diff --git a/manifests/preferences_snippet.pp b/manifests/preferences_snippet.pp index 8905318..04fb010 100644 --- a/manifests/preferences_snippet.pp +++ b/manifests/preferences_snippet.pp @@ -13,9 +13,6 @@ define apt::preferences_snippet ( } if $ensure == 'present' { - if $apt::custom_preferences == false { - fail('Trying to define a preferences_snippet with $custom_preferences set to false.') - } if $priority == undef { fail("apt::preferences_snippet requires the 'priority' argument to be set") -- cgit v1.2.3