---
- name: install programs used in jenkins.sh
  apt:
    name:
      - netcat-openbsd
      - sudo
    cache_valid_time: 3600
    update_cache: yes
    install_recommends: no

- name: ensure jenkins folder exists
  become: yes
  become_user: "{{ jenkins_user }}"
  file:
    path: "/home/{{ jenkins_user }}/jenkins"
    state: directory

- name: setup the docker-playground
  become: yes
  become_user: "{{ jenkins_user }}"
  git:
    repo: "https://gerrit.osmocom.org/docker-playground"
    dest: "/home/{{ jenkins_user }}/jenkins/docker-playground"

- name: add apt.key
  get_url:
    url: https://obs.osmocom.org/projects/osmocom/public_key
    dest: /etc/apt/trusted.gpg.d/obs.osmocom.org.asc
    # OBS webserver needs this header, returns 404 otherwise
    # https://github.com/ansible/ansible/issues/50436#issuecomment-451205256
    headers:
      Accept: '*/*'

- name: add apt repository
  apt_repository:
    repo: "deb [signed-by=/etc/apt/trusted.gpg.d/obs.osmocom.org.asc] https://downloads.osmocom.org/packages/osmocom:/latest/{{ obs_distro }}/ ./"
    filename: obs_osmocom
    update_cache: yes

- name: install libosmocore-utils
  apt:
    name:
      - libosmocore-utils
    update_cache: yes
    cache_valid_time: 3600

# Running bts ttcn3 tests as user requires them to be able to set rtprio
- name: allow jenkins user to set rtprio
  ansible.builtin.lineinfile:
    path: "/etc/security/limits.d/{{ jenkins_user }}_allow-rtprio.conf"
    line: "{{ jenkins_user }} - rtprio 30"
    create: yes
