| 1 | #
|
|---|
| 2 | class apt(
|
|---|
| 3 | $update = {},
|
|---|
| 4 | $purge = {},
|
|---|
| 5 | $proxy = {},
|
|---|
| 6 | $sources = {},
|
|---|
| 7 | $keys = {},
|
|---|
| 8 | $ppas = {},
|
|---|
| 9 | $pins = {},
|
|---|
| 10 | $settings = {},
|
|---|
| 11 | ) inherits ::apt::params {
|
|---|
| 12 |
|
|---|
| 13 | $frequency_options = ['always','daily','weekly','reluctantly']
|
|---|
| 14 | validate_hash($update)
|
|---|
| 15 | if $update['frequency'] {
|
|---|
| 16 | validate_re($update['frequency'], $frequency_options)
|
|---|
| 17 | }
|
|---|
| 18 | if $update['timeout'] {
|
|---|
| 19 | unless is_integer($update['timeout']) {
|
|---|
| 20 | fail('timeout value for update must be an integer')
|
|---|
| 21 | }
|
|---|
| 22 | }
|
|---|
| 23 | if $update['tries'] {
|
|---|
| 24 | unless is_integer($update['tries']) {
|
|---|
| 25 | fail('tries value for update must be an integer')
|
|---|
| 26 | }
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | $_update = merge($::apt::update_defaults, $update)
|
|---|
| 30 | include ::apt::update
|
|---|
| 31 |
|
|---|
| 32 | validate_hash($purge)
|
|---|
| 33 | if $purge['sources.list'] {
|
|---|
| 34 | validate_bool($purge['sources.list'])
|
|---|
| 35 | }
|
|---|
| 36 | if $purge['sources.list.d'] {
|
|---|
| 37 | validate_bool($purge['sources.list.d'])
|
|---|
| 38 | }
|
|---|
| 39 | if $purge['preferences'] {
|
|---|
| 40 | validate_bool($purge['preferences'])
|
|---|
| 41 | }
|
|---|
| 42 | if $purge['preferences.d'] {
|
|---|
| 43 | validate_bool($purge['preferences.d'])
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | $_purge = merge($::apt::purge_defaults, $purge)
|
|---|
| 47 |
|
|---|
| 48 | validate_hash($proxy)
|
|---|
| 49 | if $proxy['ensure'] {
|
|---|
| 50 | validate_re($proxy['ensure'], ['file', 'present', 'absent'])
|
|---|
| 51 | }
|
|---|
| 52 | if $proxy['host'] {
|
|---|
| 53 | validate_string($proxy['host'])
|
|---|
| 54 | }
|
|---|
| 55 | if $proxy['port'] {
|
|---|
| 56 | unless is_integer($proxy['port']) {
|
|---|
| 57 | fail('$proxy port must be an integer')
|
|---|
| 58 | }
|
|---|
| 59 | }
|
|---|
| 60 | if $proxy['https'] {
|
|---|
| 61 | validate_bool($proxy['https'])
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | $_proxy = merge($apt::proxy_defaults, $proxy)
|
|---|
| 65 |
|
|---|
| 66 | validate_hash($sources)
|
|---|
| 67 | validate_hash($keys)
|
|---|
| 68 | validate_hash($settings)
|
|---|
| 69 | validate_hash($ppas)
|
|---|
| 70 | validate_hash($pins)
|
|---|
| 71 |
|
|---|
| 72 | if $_proxy['ensure'] == 'absent' or $_proxy['host'] {
|
|---|
| 73 | apt::setting { 'conf-proxy':
|
|---|
| 74 | ensure => $_proxy['ensure'],
|
|---|
| 75 | priority => '01',
|
|---|
| 76 | content => template('apt/_conf_header.erb', 'apt/proxy.erb'),
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | $sources_list_content = $_purge['sources.list'] ? {
|
|---|
| 81 | true => "# Repos managed by puppet.\n",
|
|---|
| 82 | default => undef,
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | $preferences_ensure = $_purge['preferences'] ? {
|
|---|
| 86 | true => absent,
|
|---|
| 87 | default => file,
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | if $_update['frequency'] == 'always' {
|
|---|
| 91 | Exec <| title=='apt_update' |> {
|
|---|
| 92 | refreshonly => false,
|
|---|
| 93 | }
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | apt::setting { 'conf-update-stamp':
|
|---|
| 97 | priority => 15,
|
|---|
| 98 | content => template('apt/_conf_header.erb', 'apt/15update-stamp.erb'),
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | file { 'sources.list':
|
|---|
| 102 | ensure => file,
|
|---|
| 103 | path => $::apt::sources_list,
|
|---|
| 104 | owner => root,
|
|---|
| 105 | group => root,
|
|---|
| 106 | mode => '0644',
|
|---|
| 107 | content => $sources_list_content,
|
|---|
| 108 | notify => Class['apt::update'],
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | file { 'sources.list.d':
|
|---|
| 112 | ensure => directory,
|
|---|
| 113 | path => $::apt::sources_list_d,
|
|---|
| 114 | owner => root,
|
|---|
| 115 | group => root,
|
|---|
| 116 | mode => '0644',
|
|---|
| 117 | purge => $_purge['sources.list.d'],
|
|---|
| 118 | recurse => $_purge['sources.list.d'],
|
|---|
| 119 | notify => Class['apt::update'],
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | file { 'preferences':
|
|---|
| 123 | ensure => $preferences_ensure,
|
|---|
| 124 | path => $::apt::preferences,
|
|---|
| 125 | owner => root,
|
|---|
| 126 | group => root,
|
|---|
| 127 | mode => '0644',
|
|---|
| 128 | notify => Class['apt::update'],
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | file { 'preferences.d':
|
|---|
| 132 | ensure => directory,
|
|---|
| 133 | path => $::apt::preferences_d,
|
|---|
| 134 | owner => root,
|
|---|
| 135 | group => root,
|
|---|
| 136 | mode => '0644',
|
|---|
| 137 | purge => $_purge['preferences.d'],
|
|---|
| 138 | recurse => $_purge['preferences.d'],
|
|---|
| 139 | notify => Class['apt::update'],
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | # manage sources if present
|
|---|
| 143 | if $sources {
|
|---|
| 144 | create_resources('apt::source', $sources)
|
|---|
| 145 | }
|
|---|
| 146 | # manage keys if present
|
|---|
| 147 | if $keys {
|
|---|
| 148 | create_resources('apt::key', $keys)
|
|---|
| 149 | }
|
|---|
| 150 | # manage ppas if present
|
|---|
| 151 | if $ppas {
|
|---|
| 152 | create_resources('apt::ppa', $ppas)
|
|---|
| 153 | }
|
|---|
| 154 | # manage settings if present
|
|---|
| 155 | if $settings {
|
|---|
| 156 | create_resources('apt::setting', $settings)
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | # manage pins if present
|
|---|
| 160 | if $pins {
|
|---|
| 161 | create_resources('apt::pin', $pins)
|
|---|
| 162 | }
|
|---|
| 163 | }
|
|---|