Skip to content

Commit 1f64796

Browse files
wip
1 parent 4af2a43 commit 1f64796

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

meta/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
- runner
3131
- cicd
3232
dependencies:
33-
- role: robertdebock.epel
33+
- robertdebock.epel

tasks/install_runner.yml

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
tags:
1111
- install
1212

13-
- name: Download runner package
13+
- name: Download runner package version - "{{ runner_version }}"
1414
local_action:
1515
module: get_url
1616
url: "https://github.com/actions/runner/releases/download/v{{ runner_version }}/actions-runner-linux-x64-{{ runner_version }}.tar.gz"
1717
dest: ./actions-runner-linux.tar.gz
1818
run_once: yes
19+
when: runner_version != "latest"
1920
tags:
2021
- install
21-
22+
2223
- name: Unarchive package
2324
unarchive:
2425
src: ./actions-runner-linux.tar.gz
@@ -27,7 +28,7 @@
2728
tags:
2829
- install
2930

30-
- name: Get registration token
31+
- name: Get registration token (RUN ONCE)
3132
uri:
3233
url: "https://api.github.com/repos/{{ github_account }}/{{ github_repo }}/actions/runners/registration-token"
3334
user: "{{ github_account }}"
@@ -41,19 +42,42 @@
4142
- install
4243
- uninstall
4344

44-
# - name: Sstop and disable Github Actions Runner service if it is running
45-
# systemd:
46-
# name: "actions.runner.{{ github_account }}-{{ github_repo }}.{{ ansible_hostname }}"
47-
# state: stopped
48-
# enabled: no
49-
# tags:
50-
# - uninstall
45+
- name: Check currently registered runners (RUN ONCE)
46+
uri:
47+
url: "https://api.github.com/repos/{{ github_account }}/{{ github_repo }}/actions/runners"
48+
user: "{{ github_account }}"
49+
password: "{{ access_token }}"
50+
method: GET
51+
status_code: 200
52+
force_basic_auth: yes
53+
register: registered_runners
54+
run_once: yes
55+
tags:
56+
- install
57+
- uninstall
5158

52-
# - name: Unregister runner
53-
# command: "{{ runner_dir }}/./config.sh remove --token {{ registration.json.token }} --unattended"
54-
# become_user: "{{ runner_user }}"
55-
# tags:
56-
# - uninstall
59+
- name: Check service facts
60+
service_facts:
61+
62+
- name: Build service name
63+
set_fact:
64+
runner_service: "actions.runner.{{ github_account }}-{{ github_repo }}.{{ ansible_hostname }}"
65+
66+
- name: Stop and disable GitHub Actions Runner service
67+
systemd:
68+
name: "actions.runner.{{ github_account }}-{{ github_repo }}.{{ ansible_hostname }}"
69+
state: stopped
70+
enabled: no
71+
when: runner_service in services
72+
tags:
73+
- uninstall
74+
75+
- name: Unregister runner from the GitHub
76+
command: "{{ runner_dir }}/./config.sh remove --token {{ registration.json.token }} --unattended"
77+
become_user: "{{ runner_user }}"
78+
when: "'ansible_hostname' in '{{ registered_runners.json.name }}'"
79+
tags:
80+
- uninstall
5781

5882
- name: Register runner
5983
command: "{{ runner_dir }}/config.sh --url {{ github_server }}/{{ github_account }}/{{ github_repo }} --token {{ registration.json.token }} --unattended"

0 commit comments

Comments
 (0)