Skip to content

Commit 715dfc4

Browse files
Merge pull request #144 from MonolithProjects/feature/direct_download
Download Runner package directly to the runner node
2 parents 30dd67f + 94674f4 commit 715dfc4

11 files changed

+92
-100
lines changed

.github/RELEASE_DRAFTER.yml

+13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ categories:
1414
label: 'documentation'
1515
- title: 'CI'
1616
label: 'ci'
17+
version-resolver:
18+
major:
19+
labels:
20+
- 'major'
21+
minor:
22+
labels:
23+
- 'enhancement'
24+
- 'feature'
25+
patch:
26+
labels:
27+
- 'ci'
28+
- 'bug'
29+
default: patch
1730
change-template: '- $TITLE, by @$AUTHOR (#$NUMBER)'
1831
template: |
1932
# What's changed

README.md

-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ runner_user: "{{ lookup('env','USER') }}"
5656
# Directory where the local runner will be installed
5757
runner_dir: /opt/actions-runner
5858

59-
# Directory where the runner package will be dowloaded
60-
runner_pkg_tempdir: /tmp/gh_actions_runner
61-
6259
# Version of the GitHub Actions Runner
6360
runner_version: "latest"
6461

defaults/main.yml

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ runner_user: "{{ lookup('env','USER') }}"
55
# Directory where the local runner will be installed
66
runner_dir: /opt/actions-runner
77

8-
# Directory where the runner package will be dowloaded
9-
runner_pkg_tempdir: /tmp/gh_actions_runner
10-
118
# Version of the GitHub Actions Runner
129
runner_version: "latest"
1310

handlers/main.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
# handlers file for ansible-github_actions_runner (currently not used)
33
- name: Restart runner service
4-
service:
5-
name: "{{ runner_service }}"
6-
state: restarted
4+
ansible.builtin.service:
5+
name: "{{ runner_service }}"
6+
state: restarted

meta/main.yml

+28-39
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,29 @@
11
---
2-
galaxy_info:
3-
author: Michal Muransky
4-
role_name: github_actions_runner
5-
namespace: monolithprojects
6-
description: Deploy Github Actions private runner
7-
company: MonolithProjects
8-
license: "license (MIT)"
9-
min_ansible_version: 2.9.8
10-
platforms:
11-
- name: EL
12-
versions:
13-
- 6
14-
- 7
15-
- 8
16-
- name: Fedora
17-
versions:
18-
- 31
19-
- 32
20-
- 33
21-
- 34
22-
- 35
23-
- 36
24-
- name: Debian
25-
versions:
26-
- bullseye
27-
- buster
28-
- stretch
29-
- name: Ubuntu
30-
versions:
31-
- xenial
32-
- bionic
33-
- focal
34-
galaxy_tags:
35-
- github
36-
- actions
37-
- private
38-
- local
39-
- runner
40-
- cicd
2+
galaxy_info:
3+
author: Michal Muransky
4+
role_name: github_actions_runner
5+
namespace: monolithprojects
6+
description: Deploy Github Actions private runner
7+
company: MonolithProjects
8+
license: "license (MIT)"
9+
min_ansible_version: "2.10"
10+
platforms:
11+
- name: EL
12+
versions:
13+
- all
14+
- name: Fedora
15+
versions:
16+
- all
17+
- name: Debian
18+
versions:
19+
- all
20+
- name: Ubuntu
21+
versions:
22+
- all
23+
galaxy_tags:
24+
- github
25+
- actions
26+
- private
27+
- local
28+
- runner
29+
- cicd

tasks/assert.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
---
22
- name: Check github_account variable (RUN ONCE)
3-
assert:
3+
ansible.builtin.assert:
44
that:
55
- github_account is defined
66
fail_msg: "github_account is not defined"
77
run_once: yes
88

99
- name: Check access_token variable (RUN ONCE)
10-
assert:
10+
ansible.builtin.assert:
1111
that:
1212
- access_token is defined
1313
- access_token | length > 0
1414
fail_msg: "access_token was not found or is using an invalid format."
1515
run_once: yes
1616

1717
- name: Check runner_org variable (RUN ONCE)
18-
assert:
18+
ansible.builtin.assert:
1919
that:
2020
- runner_org | bool == True or runner_org == False
2121
fail_msg: "runner_org should be a boolean value"

tasks/collect_info.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
- block:
33
- name: Set complete API url for repo runner
4-
set_fact:
4+
ansible.builtin.set_fact:
55
github_full_api_url: "{{ github_api_url }}/repos/{{ github_owner | default(github_account) }}/{{ github_repo }}/actions/runners"
66
when: not runner_org
77

88
- name: Set complete API url for org runner
9-
set_fact:
9+
ansible.builtin.set_fact:
1010
github_full_api_url: "{{ github_api_url }}/orgs/{{ github_owner | default(github_account) }}/actions/runners"
1111
when: runner_org | bool
1212

1313
- name: Get registration token (RUN ONCE)
14-
uri:
14+
ansible.builtin.uri:
1515
url: "{{ github_full_api_url }}/registration-token"
1616
headers:
1717
Authorization: "token {{ access_token }}"
@@ -23,7 +23,7 @@
2323
run_once: yes
2424

2525
- name: Check currently registered runners for repo (RUN ONCE)
26-
uri:
26+
ansible.builtin.uri:
2727
url: "{{ github_full_api_url }}"
2828
headers:
2929
Authorization: "token {{ access_token }}"
@@ -35,6 +35,6 @@
3535
run_once: yes
3636

3737
- name: Check service facts
38-
service_facts:
38+
ansible.builtin.service_facts:
3939

4040
check_mode: false

tasks/install_deps.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
# All dependencies derived from https://github.com/actions/runner/blob/main/docs/start/envlinux.md
33
- name: Install dependencies on Debian Stretch
4-
package:
4+
ansible.builtin.package:
55
pkg:
66
- acl
77
- liblttng-ust0
@@ -14,7 +14,7 @@
1414
when: (ansible_distribution == "Debian" and ansible_distribution_major_version == "9")
1515

1616
- name: Install dependencies on Debian Buster
17-
package:
17+
ansible.builtin.package:
1818
pkg:
1919
- acl
2020
- liblttng-ust0
@@ -27,7 +27,7 @@
2727
when: (ansible_distribution == "Debian" and ansible_distribution_major_version == "10")
2828

2929
- name: Install dependencies on Debian Bullseye
30-
package:
30+
ansible.builtin.package:
3131
pkg:
3232
- acl
3333
- liblttng-ust0
@@ -40,7 +40,7 @@
4040
when: (ansible_distribution == "Debian" and ansible_distribution_major_version == "11")
4141

4242
- name: Install dependencies on Ubuntu Xenial systems
43-
package:
43+
ansible.builtin.package:
4444
pkg:
4545
- acl
4646
- liblttng-ust0
@@ -53,7 +53,7 @@
5353
when: (ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "16")
5454

5555
- name: Install dependencies on Ubuntu Bionic systems
56-
package:
56+
ansible.builtin.package:
5757
pkg:
5858
- acl
5959
- liblttng-ust0
@@ -66,7 +66,7 @@
6666
when: (ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "18")
6767

6868
- name: Install dependencies on Ubuntu Focal systems
69-
package:
69+
ansible.builtin.package:
7070
pkg:
7171
- acl
7272
- liblttng-ust0
@@ -79,7 +79,7 @@
7979
when: (ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "20")
8080

8181
- name: Install dependencies on RHEL/CentOS/Fedora systems
82-
package:
82+
ansible.builtin.package:
8383
name:
8484
- acl
8585
- lttng-ust

tasks/install_runner.yml

+23-27
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
- name: Create directory
3-
file:
3+
ansible.builtin.file:
44
path: "{{ runner_dir }}"
55
state: directory
66
mode: 0755
77
owner: "{{ runner_user }}"
88

99
- name: Find the latest runner version (RUN ONCE)
10-
uri:
10+
ansible.builtin.uri:
1111
url: "https://api.github.com/repos/{{ runner_download_repository }}/releases/latest"
1212
headers:
1313
Content-Type: "application/json"
@@ -23,50 +23,46 @@
2323
when: runner_version == "latest"
2424

2525
- name: Set runner_version variable (If latest)
26-
set_fact:
26+
ansible.builtin.set_fact:
2727
runner_version: "{{ api_response.json.tag_name | regex_replace('^v', '') }}"
2828
when: runner_version == "latest"
2929

3030
- name: Check if desired version already installed
31-
command: "grep -i {{ runner_version }} {{ runner_dir }}/bin/Runner.Listener.deps.json"
31+
ansible.builtin.command: "grep -i {{ runner_version }} {{ runner_dir }}/bin/Runner.Listener.deps.json"
3232
register: runner_installed
3333
check_mode: false
3434
changed_when: False
3535
ignore_errors: yes
3636

3737
- name: Create temporary directory for archive
38-
file:
39-
path: "{{ runner_pkg_tempdir }}"
38+
ansible.builtin.tempfile:
4039
state: directory
41-
recurse: yes
42-
mode: 0777
43-
run_once: yes
44-
delegate_to: localhost
40+
suffix: runner
4541
become: false
42+
register: temp_dir
4643
when: runner_version not in runner_installed.stdout
4744

4845
- name: Download runner package version - "{{ runner_version }}" (RUN ONCE)
49-
get_url:
46+
ansible.builtin.get_url:
5047
url:
5148
"https://github.com/{{ runner_download_repository }}/releases/download/v{{ runner_version }}/\
5249
actions-runner-linux-{{ github_actions_architecture }}-{{ runner_version }}.tar.gz"
53-
dest: "{{ runner_pkg_tempdir }}/actions-runner-linux-{{ runner_version }}.tar.gz"
50+
dest: "{{ temp_dir.path }}/actions-runner-linux-{{ runner_version }}.tar.gz"
5451
force: no
55-
run_once: yes
5652
become: false
57-
delegate_to: localhost
5853
when: runner_version not in runner_installed.stdout or reinstall_runner
5954

6055
- name: Unarchive package
61-
unarchive:
62-
src: "{{ runner_pkg_tempdir }}/actions-runner-linux-{{ runner_version }}.tar.gz"
56+
ansible.builtin.unarchive:
57+
src: "{{ temp_dir.path }}/actions-runner-linux-{{ runner_version }}.tar.gz"
6358
dest: "{{ runner_dir }}/"
6459
owner: "{{ runner_user }}"
60+
remote_src: yes
6561
mode: 0755
6662
when: runner_version not in runner_installed.stdout or reinstall_runner
6763

6864
- name: Configure custom env file if required
69-
blockinfile:
65+
ansible.builtin.blockinfile:
7066
path: "{{ runner_dir }}/.env"
7167
block: "{{ custom_env }}"
7268
owner: "{{ runner_user }}"
@@ -77,22 +73,22 @@
7773
when: custom_env is defined
7874

7975
- name: Check if runner service name file exist
80-
stat:
76+
ansible.builtin.stat:
8177
path: "{{ runner_dir }}/.service"
8278
register: runner_service_file_path
8379

8480
- name: Set complete GitHub url for repo runner
85-
set_fact:
81+
ansible.builtin.set_fact:
8682
github_full_url: "{{ github_url }}/{{ github_owner | default(github_account) }}/{{ github_repo }}"
8783
when: not runner_org
8884

8985
- name: Set complete GitHub url for org runner
90-
set_fact:
86+
ansible.builtin.set_fact:
9187
github_full_url: "{{ github_url }}/{{ github_owner | default(github_account) }}"
9288
when: runner_org | bool
9389

9490
- name: Register runner
95-
command:
91+
ansible.builtin.command:
9692
"{{ runner_dir }}/./config.sh \
9793
--url {{ github_full_url }} \
9894
--token {{ registration.json.token }} \
@@ -109,7 +105,7 @@
109105
when: runner_name not in registered_runners.json.runners|map(attribute='name')|list
110106

111107
- name: Replace registered runner
112-
command:
108+
ansible.builtin.command:
113109
"{{ runner_dir }}/config.sh \
114110
--url {{ github_full_url }} \
115111
--token {{ registration.json.token }} \
@@ -126,34 +122,34 @@
126122
when: runner_name in registered_runners.json.runners|map(attribute='name')|list and reinstall_runner and not runner_org
127123

128124
- name: Install service
129-
command: "./svc.sh install {{ runner_user }}"
125+
ansible.builtin.command: "./svc.sh install {{ runner_user }}"
130126
args:
131127
chdir: "{{ runner_dir }}"
132128
when: not runner_service_file_path.stat.exists
133129

134130
- name: Read service name from file
135-
slurp:
131+
ansible.builtin.slurp:
136132
src: "{{ runner_dir }}/.service"
137133
register: runner_service
138134

139135
- name: START and enable Github Actions Runner service
140-
systemd:
136+
ansible.builtin.systemd:
141137
name: "{{ runner_service.content | b64decode | replace('\n', '') }}"
142138
state: started
143139
enabled: yes
144140
ignore_errors: "{{ ansible_check_mode }}"
145141
when: runner_state|lower == "started"
146142

147143
- name: STOP and disable Github Actions Runner service
148-
systemd:
144+
ansible.builtin.systemd:
149145
name: "{{ runner_service.content | b64decode | replace('\n', '') }}"
150146
state: stopped
151147
enabled: no
152148
ignore_errors: "{{ ansible_check_mode }}"
153149
when: runner_state|lower == "stopped"
154150

155151
- name: Version changed - RESTART Github Actions Runner service
156-
systemd:
152+
ansible.builtin.systemd:
157153
name: "{{ runner_service.content | b64decode | replace('\n', '') }}"
158154
state: restarted
159155
ignore_errors: "{{ ansible_check_mode }}"

0 commit comments

Comments
 (0)