security-ubuntu.yml 1.67 KB
Newer Older
1
---
2
#### Enable periodic security updates
3 4 5 6 7 8
- name: Install security packages
  apt:
    name: "{{ item }}"
    state: latest
    update_cache: yes
  with_items: "{{ security_debian_pkgs }}"
9 10


11 12 13
- name: Update all system packages
  apt:
    upgrade: safe
14
  when: SAFE_UPGRADE_ON_ANSIBLE
15

16 17 18 19 20 21 22
- name: Configure periodic unattended-upgrades
  template:
    src: "etc/apt/apt.conf.d/10periodic"
    dest: "/etc/apt/apt.conf.d/10periodic"
    owner: root
    group: root
    mode: "0644"
23 24
  when: SECURITY_UNATTENDED_UPGRADES

25 26 27 28 29 30 31
- name: Disable unattended-upgrades if Xenial (16.04)
  command: "{{ item }}"
  when: ansible_distribution_release == 'xenial' and not SECURITY_UNATTENDED_UPGRADES
  with_items:
    - "systemctl disable apt-daily.service"
    - "systemctl disable apt-daily.timer"

32 33 34 35
- name: Disable unattended-upgrades
  file:
    path: "/etc/apt/apt.conf.d/10periodic"
    state: absent
36 37
  when: not SECURITY_UNATTENDED_UPGRADES

38 39 40 41 42 43 44
- name: Only unattended-upgrade from security repo
  template:
    src: "etc/apt/apt.conf.d/20unattended-upgrade"
    dest: "/etc/apt/apt.conf.d/20unattended-upgrade"
    owner: root
    group: root
    mode: "0644"
45 46
  when: SECURITY_UNATTENDED_UPGRADES and not SECURITY_UPDATE_ALL_PACKAGES

47 48 49 50
- name: Disable security only updates on unattended-upgrades
  file:
    path: "/etc/apt/apt.conf.d/20unattended-upgrade"
    state: absent
51 52
  when: SECURITY_UPDATE_ALL_PACKAGES or not SECURITY_UNATTENDED_UPGRADES

53 54 55 56 57 58 59
# We dry-run because unattended-upgrade is quiet, and only had -d (debug) not -v (verbose)
- name: "Take security updates during ansible runs"
  command: "{{ item }}"
  when: SECURITY_UPGRADE_ON_ANSIBLE
  with_items:
    - unattended-upgrade --dry-run
    - unattended-upgrade