---

- name: install jenkins packages
  include_tasks: debian.yml
  when: ansible_distribution == 'Debian'

# Raspbian default user "pi" has uid=1000, which we need for the jenkins user.
# When the ansible playbook is running, root access via ssh is already
# configured, so we don't need the user "pi" anymore.
- name: delete raspbian default user
  user:
    name: "pi"
    remove: true
    state: absent

- name: add user jenkins
  user:
    name: "{{ jenkins_user }}"
    generate_ssh_key: yes
    ssh_key_bits: 4096
    ssh_key_type: rsa
    shell: /bin/bash
    uid: 1000

- name: setup jenkins ssh key (authorized_keys)
  authorized_key:
    user: "{{ jenkins_user }}"
    key: "{{ lookup('file', 'jenkins.osmocom.org.pub') }}"

- name: setup gerrit ssh key (known_hosts)
  known_hosts:
    name: '[gerrit.osmocom.org]:29418'
    key: '[gerrit.osmocom.org]:29418 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDI4wZwtcGz2V98iZWWEtsA162PolLtgQTBjnC14ONzZGQkTh9bTPsoSxnM5TKOm4F2bzq7gb+Qrsj4ZECD19qztmD37kMP9jn7/2i1V8oLAy9ojyklXAdBVTliQteVI7ieDOyKCnGbszvFWXY2isoO1k7yJLv0QyL7F5AuZlxeHw=='
    path: /etc/ssh/ssh_known_hosts
    state: present

- name: install ttcn3 dependencies
  include_tasks: ttcn3-slave.yml
  when: ttcn3_slave and ansible_distribution == 'Debian' and ansible_distribution_version|int >= 9 and not (ansible_architecture == "armv7l" or ansible_architecture == "arm64")

- name: include generic slave
  include_tasks: generic-slave.yml
  when: generic_slave

- name: set-up osmo-ci repo
  include_tasks: osmo-ci.yml
  when: generic_slave

- name: copy .gitconfig
  copy:
    src: gitconfig
    dest: "/home/{{ jenkins_user }}/.gitconfig"

- name: call fstrim periodically
  cron:
    name: "fstrim"
    hour: "*/12"
    minute: 0
    job: "fstrim / >/dev/null 2>/dev/null || true"
  when: osmocom_jenkins_slave_fstrim

- name: add tmpfs for /home/osmocom-build/jenkins
  when: jenkins_tmpfs
  ansible.posix.mount:
    boot: true
    path: /home/osmocom-build/jenkins
    src: tmpfs
    fstype: tmpfs
    state: mounted
    opts: "uid=1000,gid=1000"

- name: add tmpfs for /home/osmocom-build/ccache
  when: jenkins_tmpfs
  ansible.posix.mount:
    boot: true
    path: /home/osmocom-build/ccache
    src: tmpfs
    fstype: tmpfs
    state: mounted
    opts: "uid=1000,gid=1000"