Skip to content

Commit 3dd9396

Browse files
Direct download and FQCN
1 parent 30dd67f commit 3dd9396

File tree

10 files changed

+52
-62
lines changed

10 files changed

+52
-62
lines changed

README.md

Lines changed: 0 additions & 3 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
description: Deploy Github Actions private runner
77
company: MonolithProjects
88
license: "license (MIT)"
9-
min_ansible_version: 2.9.8
9+
min_ansible_version: 2.10
1010
platforms:
1111
- name: EL
1212
versions:

tasks/assert.yml

Lines changed: 3 additions & 3 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 23 additions & 27 deletions
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 }}"

tasks/main.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
---
22
- name: Include Assert tasks
3-
include_tasks: assert.yml
3+
ansible.builtin.include_tasks: assert.yml
44
tags:
55
- install
66
- uninstall
77

88
- name: Include Information collection taks
9-
include_tasks: collect_info.yml
9+
ansible.builtin.include_tasks: collect_info.yml
1010
tags:
1111
- install
1212
- uninstall
1313

1414
- name: Include tasks to install dependencies
15-
include_tasks: install_deps.yml
15+
ansible.builtin.include_tasks: install_deps.yml
1616
when: runner_state|lower == "started" or runner_state|lower == "stopped"
1717
tags:
1818
- install
1919

2020
- name: Include tasks to uninstall runner
21-
include_tasks: uninstall_runner.yml
21+
ansible.builtin.include_tasks: uninstall_runner.yml
2222
when: reinstall_runner or runner_state|lower == "absent"
2323
tags:
2424
- uninstall
2525

2626
- name: Include tasks to install runner
27-
include_tasks: install_runner.yml
27+
ansible.builtin.include_tasks: install_runner.yml
2828
when: runner_state|lower == "started" or runner_state|lower == "stopped"
2929
tags:
3030
- install

tasks/uninstall_runner.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
---
22
- name: Check if runner service name file exist
3-
stat:
3+
ansible.builtin.stat:
44
path: "{{ runner_dir }}/.service"
55
register: runner_service_file_path
66

77
- name: Uninstall runner
8-
command: "./svc.sh uninstall"
8+
ansible.builtin.command: "./svc.sh uninstall"
99
args:
1010
chdir: "{{ runner_dir }}"
1111
become: yes
1212
when: runner_service_file_path.stat.exists
1313

1414
- name: Check GitHub Actions runner file
15-
stat:
15+
ansible.builtin.stat:
1616
path: "{{ runner_dir }}/.runner"
1717
register: runner_file
1818

1919
- name: Unregister runner from the GitHub
20-
command: "./config.sh remove --token {{ registration.json.token }} --name '{{ runner_name }}' --unattended"
20+
ansible.builtin.command: "./config.sh remove --token {{ registration.json.token }} --name '{{ runner_name }}' --unattended"
2121
args:
2222
chdir: "{{ runner_dir }}"
2323
become: yes
@@ -26,6 +26,6 @@
2626
when: runner_name in registered_runners.json.runners|map(attribute='name')|list and runner_file.stat.exists
2727

2828
- name: Delete runner directory
29-
file:
29+
ansible.builtin.file:
3030
path: "{{ runner_dir }}"
3131
state: absent

0 commit comments

Comments
 (0)