jnv / ansible-role-unattended-upgrades

[DEPRECATED] Setup unattended-upgrades on Debian-based systems
https://github.com/jnv/ansible-role-unattended-upgrades/issues/98
GNU General Public License v2.0
272 stars 94 forks source link

⚠️ This role is deprecated! See the GitHub issue for explanation and maintained fork of this role.

Unattended-Upgrades Role for Ansible

Build Status of branch master Ansible Role: jnv.unattended-upgrades

Install and setup unattended-upgrades for Ubuntu and Debian (since Wheezy), to periodically install security upgrades.

NOTE: If you have used version 0.0.1 of the role, you can delete the file /etc/apt/apt.conf.d/10periodic as it is not needed anymore. You can use the following one-shot command:

ansible -m file -a "state=absent path=/etc/apt/apt.conf.d/10periodic" <host-pattern>

Requirements

The role uses apt module which has additional dependencies.

If you set unattended_mail to an e-mail address, make sure mailx command is available and your system is able to send e-mails.

The role requires unattended-upgrades version 0.70 and newer, which is available since Debian Wheezy and Ubuntu 12.04 respectively. This is due to Origins Patterns usage; if this is not available on your system, you may use the first version of the role.

Automatic Reboot

If you enable automatic reboot feature (unattended_automatic_reboot), the role will attempt to install update-notifier-common package, which is required on some systems for detecting and executing reboot after the upgrade. You may optionally define a specific time for rebooting (unattended_automatic_reboot_time).

This feature was broken in Debian Jessie, but eventually was rolled into the unattended-upgrades package; see the discussion in #6 for more details.

Disabled Cron Jobs

On some hosts you may find that the unattended-upgrade's cronfile /etc/cron.daily/apt file has been renamed to apt.disabled. This is possibly provider's decision, to save some CPU cycles. Use enable-standard-cronjobs role to reenable unattended-upgrades. See also discussion in #9.

Role Variables

Origins Patterns

Origins Pattern is a more powerful alternative to the Allowed Origins option used in previous versions of unattended-upgrade.

Pattern is composed from specific keywords:

You can review the available repositories using apt-cache policy and debug your choice using unattended-upgrades -d command on a target system.

Additionally unattended-upgrades support two macros (variables), derived from /etc/debian_version:

Using ${distro_codename} should be preferred over using stable or oldstable as a selected, as once stable moves to oldstable, no security updates will be installed at all, or worse, package from a newer distro release will be installed by accident. The same goes for upgrading your installation from oldstable to stable, if you forget to change this in your origin patterns, you may not receive the security updates for your newer distro release. With ${distro_codename}, both cases can never happen.

Role Usage Examples

Example for Ubuntu, with custom origins patterns, blacklisted packages and e-mail notification:

- hosts: all
  roles:
  - role: jnv.unattended-upgrades
    unattended_origins_patterns:
    - 'origin=Ubuntu,archive=${distro_codename}-security'
    - 'o=Ubuntu,a=${distro_codename}-updates'
    unattended_package_blacklist: [cowsay, vim]
    unattended_mail: 'root@example.com'

Note: You don't need to specify unattended_origins_patterns, the role will use distribution's default if the variable is not set.

Running Only on Debian-based Systems

If you manage multiple distribution with the same playbook, you may want to skip running this role on non-Debian systems. You can use when conditional with role to limit the role to particular systems:

- hosts: all
  roles:
     - role: jnv.unattended-upgrades
       when: ansible_facts['os_family'] == 'Debian'

See #38 for discussion.

Patterns Examples

By default, only security updates are allowed for both Ubuntu and Debian. You can add more patterns to allow unattended-updates install more packages automatically, however be aware that automated major updates may potentially break your system.

For Debian

unattended_origins_patterns:
  - 'origin=Debian,codename=${distro_codename},label=Debian-Security' # security updates
  - 'o=Debian,codename=${distro_codename},label=Debian' # updates including non-security updates
  - 'o=Debian,codename=${distro_codename},a=proposed-updates'

On debian wheezy, due to unattended-upgrades being 0.79.5, you cannot use the codename directive.

You will have to do archive based matching instead:

unattended_origins_patterns:
  - 'origin=Debian,a=stable,label=Debian-Security' # security updates
  - 'o=Debian,a=stable,l=Debian' # updates including non-security updates
  - 'o=Debian,a=proposed-updates'

Please be sure to read about the issues regarding this in the origin pattern documentation above.

For Ubuntu

In Ubuntu, archive always contains the distribution codename

unattended_origins_patterns:
  - 'origin=Ubuntu,archive=${distro_codename}-security'
  - 'o=Ubuntu,a=${distro_codename}'
  - 'o=Ubuntu,a=${distro_codename}-updates'
  - 'o=Ubuntu,a=${distro_codename}-proposed-updates'

For Raspbian

In Raspbian, it is only possible to update all packages from the default repository, including non-security updates, or updating none.

Updating all, including non-security:

unattended_origins_patterns:
  - 'origin=Raspbian,codename=${distro_codename},label=Raspbian'

You can not use the codename directive on raspbian wheezy, the same as with debian wheezy above.

To not install any updates on a raspbian host, just set unattended_origins_patterns to an empty list:

unattended_origins_patterns: []

License

GPLv2