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