Remove stderr from stdout
[puppet-modules/puppetlabs-apt.git] / manifests / update.pp
1 class apt::update {
2   include apt::params
3   #TODO: to catch if $::apt_update_last_success has the value of -1 here. If we
4   #opt to do this, a info/warn would likely be all you'd need likely to happen
5   #on the first run, but if it's not run in awhile something is likely borked
6   #with apt and we'd want to know about it.
7
8   if $::apt::always_apt_update == false {
9     #if always_apt_update is true there's no point in parsing this logic.
10
11     case $apt::apt_update_frequency {
12       'always': {
13         $_kick_apt = true
14       }
15       'daily': {
16         #compare current date with the apt_update_last_success fact to determine
17         #if we should kick apt_update.
18         $daily_threshold = (strftime('%s') - 86400)
19         if $::apt_update_last_success {
20           if $::apt_update_last_success < $daily_threshold {
21             $_kick_apt = true
22           }
23         } else {
24           #if apt-get update has not successfully run, we should kick apt_update
25           $_kick_apt = true
26         }
27       }
28       'weekly':{
29         #compare current date with the apt_update_last_success fact to determine
30         #if we should kick apt_update.
31         $weekly_threshold = (strftime('%s') - 604800)
32         if $::apt_update_last_success {
33           if ( $::apt_update_last_success < $weekly_threshold ) {
34             $_kick_apt = true
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 'recluctantly', and any other value (which should not occur).
43         #do nothing.
44       }
45     }
46   }
47   if $_kick_apt {
48     $_refresh = false
49   } else {
50     $_refresh = true
51   }
52   exec { 'apt_update':
53     command     => "${apt::params::provider} update",
54     logoutput   => 'on_failure',
55     refreshonly => $_refresh,
56     timeout     => $apt::update_timeout,
57     tries       => $apt::update_tries,
58     try_sleep   => 1
59   }
60 }