aboutsummaryrefslogtreecommitdiff
path: root/roles/gitea_runner/tasks/main.yml
blob: b050a12ebdf8b6989688a6219ef0c4bdfbdafcb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
- name: Install packages
  apt:
    name:
      - docker.io
  become: true

- name: Create User
  user:
    name: runner
    system: true
    state: present
    groups:
      - docker
  become: true

- name: Folder structure
  file:
    path: '{{ item }}'
    owner: runner
    group: runner
    mode: '750'
    state: directory
  become: true
  loop:
    - /var/lib/act_runner/
    - /etc/act_runner/

- name: Configuration
  copy:
    dest: /etc/act_runner/config.yaml
    owner: runner
    group: runner
    content: '{{ gitea_runner.config | to_yaml }}'
  become: true

- name: pull sha256sum
  uri:
    url: 'https://dl.gitea.io/act_runner/{{ gitea_runner.version.ver }}/act_runner-{{ gitea_runner.version.ver }}-linux-amd64.sha256'
    method: GET
    return_content: yes
  register: runner_sha256

- name: Download Gitea act_runner
  get_url:
    url: 'https://dl.gitea.io/act_runner/{{ gitea_runner.version.ver }}/act_runner-{{ gitea_runner.version.ver }}-linux-amd64'
    checksum: 'sha256:{{ (runner_sha256.content | split(" "))[0] }}'
    dest: /usr/local/bin/act_runner
    owner: root
    group: root
    mode: '755'
  become: yes
  notify:
    - Handle systemd

- name: Install gitea unit file
  copy:
    src: act_runner.service
    dest: /etc/systemd/system/act_runner.service
  become: yes
  notify:
    - Handle systemd

- debug:
    msg: '--labels {% for k, v in gitea_runner.tags.items() %}{{ k }}:{{ v }},{% endfor %}'


- name: Register runner
  shell:
    cmd: '/usr/local/bin/act_runner -c /etc/act_runner/config.yaml register --instance {{ gitea_runner.gitea_url }} --token {{ gitea_runner.runner_token }} --no-interactive --labels {% for k, v in gitea_runner.tags.items() %}{{ k }}:{{ v }},{% endfor %}'
    creates: '/var/lib/act_runner/runner.conf'
  become_user: runner
  become: true
  notify:
    - Handle systemd

- name: Configure labels
  lineinfile:
    path: '/var/lib/act_runner/runner.conf'
    state: present
    insertafter: '"labels"'
    line: '    "{{ item.key }}:{{ item.value }}",'
    search_string: '    "{{ item.key }}:{{ item.value }}",'
  with_dict: '{{ gitea_runner.tags }}'
  become: true
  notify:
    - Handle systemd