main.yml 663 B

123456789101112131415161718192021222324252627
  1. ---
  2. - name: Install unattended-upgrades package
  3. apt:
  4. pkg: "unattended-upgrades"
  5. state: present
  6. update_cache: yes
  7. cache_valid_time: 1800
  8. - name: Enable unattended upgrades
  9. template:
  10. src: 10periodic.j2
  11. dest: /etc/apt/apt.conf.d/10periodic
  12. - name: Configure unattended upgrades
  13. template:
  14. src: 50unattended-upgrades.j2
  15. dest: /etc/apt/apt.conf.d/50unattended-upgrades
  16. - name: Let restart server once a week but not all at the same time
  17. cron:
  18. name: weekly restart
  19. weekday: "{{(vm_id-2)%7}}"
  20. hour: "3"
  21. minute: "{{(vm_id*2)%30+30}}"
  22. job: "if [ -f /var/run/reboot-required ]; then /sbin/shutdown -r +5; fi"