update.pp 2.0 KB

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