---
- name:           Domain
  debug:          var=domain

- name:           Stage
  debug:          var=stage

- name:           New Hostname
  debug:          var=new_hostname

- name:           Update apt cache
  apt:            update_cache=yes cache_valid_time="{{ 60 * 60 * 24 }}"
  sudo:           yes

- name:           Autoremove unused packages
  shell:          DEBIAN_FRONTEND=noninteractive apt-get -y autoremove
  sudo:           yes

- name:           Install common packages
  apt:            pkg={{ item }} state=present
  with_items:     common_packages
  sudo:           yes

- name:           Update `hostname`
  hostname:       name="{{ new_hostname }}"
  sudo:           yes
  when:           old_hostname != new_hostname

- name:           Update /etc/hosts
  replace:        dest=/etc/hosts backup=yes regexp={{ old_hostname | replace(".", "[.]") }} replace={{ new_hostname }}
  sudo:           yes
  when:           old_hostname != new_hostname

- name:           Configure logrotate for evolution logs
  copy:           src=logrotate dest=/etc/logrotate.d/evolution mode=0644
  sudo:           yes

- include:        swap.yml
  when:           ansible_swaptotal_mb == 0

---
- name:           Domain
  debug:          var=domain

- name:           Stage
  debug:          var=stage

- name:           New Hostname
  debug:          var=new_hostname

- name:           Fetch kernel purging script
  get_url:
    url:          https://raw.githubusercontent.com/EvanK/ubuntu-purge-kernels/master/purge-kernels.py
    dest:         /tmp/purge-kernels.py
    mode:         0755
    force:        yes

- name:           Purge kernels as necessary
  command:        /tmp/purge-kernels.py
  register:       purgekernels_result
  ignore_errors:  yes
  sudo:           yes

- name:           Show purged kernels
  debug:          var=purgekernels_result

- name:           Update apt cache
  apt:            update_cache=yes cache_valid_time="{{ 60 * 60 * 24 }}"
  sudo:           yes

- name:           Autoremove unused packages
  shell:          DEBIAN_FRONTEND=noninteractive apt-get -y autoremove
  sudo:           yes

- name:           Install common packages
  apt:            pkg={{ item }} state=present
  with_items:     common_packages
  sudo:           yes

- name:           Update `hostname`
  hostname:       name="{{ new_hostname }}"
  sudo:           yes
  when:           old_hostname != new_hostname

- name:           Update /etc/hosts
  replace:        dest=/etc/hosts backup=yes regexp={{ old_hostname | replace(".", "[.]") }} replace={{ new_hostname }}
  sudo:           yes
  when:           old_hostname != new_hostname

- name:           Configure logrotate for evolution logs
  copy:           src=logrotate dest=/etc/logrotate.d/evolution mode=0644
  sudo:           yes

- include:        swap.yml
  when:           ansible_swaptotal_mb == 0

Purge old kernels if boot partition is close to full
Purge old kernels if boot partition is close to full
