Allow user to modify loglevel of apt-get update Exec resource so that its
[puppet-modules/puppetlabs-apt.git] / manifests / update.pp
1 class apt::update {
2   #TODO: to catch if $::apt_update_last_success has the value of -1 here. If we
3   #opt to do this, a info/warn would likely be all you'd need likely to happen
4   #on the first run, but if it's not run in awhile something is likely borked
5   #with apt and we'd want to know about it.
6
7   case $::apt::_update['frequency'] {
8     'always': {
9       $_kick_apt = true
10     }
11     'daily': {
12       #compare current date with the apt_update_last_success fact to determine
13       #if we should kick apt_update.
14       $daily_threshold = (strftime('%s') - 86400)
15       if $::apt_update_last_success {
16         if $::apt_update_last_success + 0 < $daily_threshold {
17           $_kick_apt = true
18         } else {
19           $_kick_apt = false
20         }
21       } else {
22         #if apt-get update has not successfully run, we should kick apt_update
23         $_kick_apt = true
24       }
25     }
26     'weekly':{
27       #compare current date with the apt_update_last_success fact to determine
28       #if we should kick apt_update.
29       $weekly_threshold = (strftime('%s') - 604800)
30       if $::apt_update_last_success {
31         if ( $::apt_update_last_success + 0 < $weekly_threshold ) {
32           $_kick_apt = true
33         } else {
34           $_kick_apt = false
35         }
36       } else {
37         #if apt-get update has not successfully run, we should kick apt_update
38         $_kick_apt = true
39       }
40     }
41     default: {
42       #catches 'reluctantly', and any other value (which should not occur).
43       #do nothing.
44       $_kick_apt = false
45     }
46   }
47
48   if $_kick_apt {
49     $_refresh = false
50   } else {
51     $_refresh = true
52   }
53   exec { 'apt_update':
54     command     => "${::apt::provider} update",
55     loglevel    => $::apt::_update['loglevel'],
56     logoutput   => 'on_failure',
57     refreshonly => $_refresh,
58     timeout     => $::apt::_update['timeout'],
59     tries       => $::apt::_update['tries'],
60     try_sleep   => 1
61   }
62 }