update.pp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. } else {
  21. $_kick_apt = false
  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. } else {
  36. $_kick_apt = false
  37. }
  38. } else {
  39. #if apt-get update has not successfully run, we should kick apt_update
  40. $_kick_apt = true
  41. }
  42. }
  43. default: {
  44. #catches 'recluctantly', and any other value (which should not occur).
  45. #do nothing.
  46. $_kick_apt = false
  47. }
  48. }
  49. } else {
  50. $_kick_apt = false
  51. }
  52. if $_kick_apt {
  53. $_refresh = false
  54. } else {
  55. $_refresh = true
  56. }
  57. exec { 'apt_update':
  58. command => "${apt::params::provider} update",
  59. logoutput => 'on_failure',
  60. refreshonly => $_refresh,
  61. timeout => $apt::update_timeout,
  62. tries => $apt::update_tries,
  63. try_sleep => 1
  64. }
  65. }