main.yml 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. ---
  2. - name: Linux Updates
  3. block:
  4. - name: update apt cache
  5. apt:
  6. update_cache: yes
  7. # cache_valid_time: 0
  8. - name: read upgradable packages
  9. shell: apt list --upgradable
  10. register: apt_upgradeable
  11. changed_when: false
  12. - name: upgrade a server
  13. apt:
  14. #update_cache: yes
  15. upgrade: dist
  16. register: apt_upgrade
  17. ignore_errors: True
  18. - name: delete old packages
  19. apt: autoclean=yes
  20. register: apt_autoclean
  21. - name: check for deleted files
  22. shell: lsof +L1 -R
  23. register: lsof
  24. #- debug: var=apt_upgrade
  25. # with_items:
  26. # - apt_autoclean
  27. # - apt_upgrade
  28. # - lsof
  29. ## set color green
  30. - set_fact:
  31. color: "#00CC33"
  32. title_status: "successfully"
  33. when: apt_upgrade.failed == false
  34. - mail:
  35. subject: "[U] {{ ansible_fqdn }} # updated {{ title_status }}"
  36. to: update <erdo@ichalsroot.de>
  37. body: "{{ lookup('template', 'templates/mail_body.j2') }}"
  38. subtype: html
  39. delegate_to: localhost
  40. when: apt_upgrade.changed or apt_upgrade.failed == true
  41. when: ansible_os_family == "Debian"