---

- block:

  - include_vars:
      file: vars/chrony.yml

  - name: Install debug symbols apt repository key
    apt_key:
      data: "{{ lookup('file', 'dbgsym-release-key.asc') }}"
      state: present

  - name: Add debug symbols apt repository for trusty
    apt_repository:
      repo: "deb [arch=amd64] {{ apt_mirror_base_url }}/ddebs.ubuntu.com/ trusty main restricted universe multiverse"
      state: present
      filename: "ddebs"

  - name: Add debug symbols apt repository for trusty-updates
    apt_repository:
      repo: "deb [arch=amd64] {{ apt_mirror_base_url }}/ddebs.ubuntu.com/ trusty-updates main restricted universe multiverse"
      state: present
      filename: "ddebs_updates"

  - name: Add debug symbols apt repository for trusty-proposed
    apt_repository:
      repo: "deb [arch=amd64] {{ apt_mirror_base_url }}/ddebs.ubuntu.com/ trusty-proposed main restricted universe multiverse"
      state: present
      filename: "ddebs_proposed"

  - name: Update apt cache for debug symbols apt repositories
    apt:
      update_cache: yes
      cache_valid_time: "{{ apt_cache_valid_time }}"

  - name: Install system tools packages from apt
    apt:
      name:
        - "adjtimex"
        - "cgroup-bin"
        - "cgroup-lite"
        - "clusterssh"
        - "cpufrequtils"
        - "cryptsetup"
        - "dpkg"
        - "hddtemp"
        - "htop"
        - "iftop"
        - "iotop"
        - "lm-sensors"
        - "numactl"
        - "openssh-client"
        - "openssh-server"
        - "pps-tools"
        - "smartmontools"
        # Dependencies for chrony
        - "libtomcrypt0"
        - "timelimit"
        - "install-info"
      install_recommends: no
      state: present

  - name: Install Chrony
    # Chrony built from https://git.zooxlabs.com/zooxco/chrony , following the directions in that repository
    http_deb:
      name: chrony
      version: "{{ chrony_version }}"
      url: "{{ chrony_download_url }}"
      checksum: "sha256:{{ chrony_sha }}"
    become: yes

  - name: Allow perf recording without root
    sysctl:
      name: "{{ item.name }}"
      value: "{{ item.value }}"
      sysctl_set: yes
      state: present
      reload: yes
    with_items: "{{ perf_without_root_sysctl }}"
    when: ansible_virtualization_type != "docker"

  become: yes
