update.pp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. case $::apt::_update['frequency'] {
  7. 'always': {
  8. $_kick_apt = true
  9. }
  10. 'daily': {
  11. #compare current date with the apt_update_last_success fact to determine
  12. #if we should kick apt_update.
  13. $daily_threshold = (strftime('%s') - 86400)
  14. if $::apt_update_last_success {
  15. if $::apt_update_last_success < $daily_threshold {
  16. $_kick_apt = true
  17. } else {
  18. $_kick_apt = false
  19. }
  20. } else {
  21. #if apt-get update has not successfully run, we should kick apt_update
  22. $_kick_apt = true
  23. }
  24. }
  25. 'weekly':{
  26. #compare current date with the apt_update_last_success fact to determine
  27. #if we should kick apt_update.
  28. $weekly_threshold = (strftime('%s') - 604800)
  29. if $::apt_update_last_success {
  30. if ( $::apt_update_last_success < $weekly_threshold ) {
  31. $_kick_apt = true
  32. } else {
  33. $_kick_apt = false
  34. }
  35. } else {
  36. #if apt-get update has not successfully run, we should kick apt_update
  37. $_kick_apt = true
  38. }
  39. }
  40. default: {
  41. #catches 'reluctantly', and any other value (which should not occur).
  42. #do nothing.
  43. $_kick_apt = false
  44. }
  45. }
  46. if $_kick_apt {
  47. $_refresh = false
  48. } else {
  49. $_refresh = true
  50. }
  51. exec { 'apt_update':
  52. command => "${::apt::provider} update",
  53. logoutput => 'on_failure',
  54. refreshonly => $_refresh,
  55. timeout => $::apt::_update['timeout'],
  56. tries => $::apt::_update['tries'],
  57. try_sleep => 1
  58. }
  59. }