update.pp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. if $::apt::always_apt_update == false {
  8. #if always_apt_update is true there's no point in parsing this logic.
  9. case $apt::apt_update_frequency {
  10. 'always': {
  11. $_kick_apt = true
  12. }
  13. 'daily': {
  14. #compare current date with the apt_update_last_success fact to determine
  15. #if we should kick apt_update.
  16. $daily_threshold = (strftime('%s') - 86400)
  17. if $::apt_update_last_success {
  18. if $::apt_update_last_success < $daily_threshold {
  19. $_kick_apt = true
  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 < $weekly_threshold ) {
  32. $_kick_apt = true
  33. }
  34. } else {
  35. #if apt-get update has not successfully run, we should kick apt_update
  36. $_kick_apt = true
  37. }
  38. }
  39. default: {
  40. #catches 'recluctantly', and any other value (which should not occur).
  41. #do nothing.
  42. }
  43. }
  44. }
  45. if $_kick_apt {
  46. $_refresh = false
  47. } else {
  48. $_refresh = true
  49. }
  50. exec { 'apt_update':
  51. command => "${apt::params::provider} update",
  52. logoutput => 'on_failure',
  53. refreshonly => $_refresh,
  54. timeout => $apt::update_timeout,
  55. tries => $apt::update_tries,
  56. try_sleep => 1
  57. }
  58. }