Skip to content

Commit 65b15a8

Browse files
feat: add macos support
1 parent 6f2b964 commit 65b15a8

File tree

5 files changed

+81
-50
lines changed

5 files changed

+81
-50
lines changed

defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
# Runner user - user under which is the local runner service running
3-
runner_user: "{{ lookup('env','USER') }}"
3+
runner_user: "{{ lookup('env', 'USER') }}"
44

55
# Directory where the local runner will be installed
66
runner_dir: /opt/actions-runner

tasks/collect_info.yml

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
2-
- block:
2+
- name: Info collections
3+
check_mode: false
4+
block:
35
- name: Set complete API url for repo runner
46
ansible.builtin.set_fact:
57
github_full_api_url: "{{ github_api_url }}/repos/{{ github_owner | default(github_account) }}/{{ github_repo }}/actions/runners"
@@ -34,12 +36,37 @@
3436
register: registered_runners
3537
run_once: true
3638

37-
- name: Check service facts
38-
ansible.builtin.service_facts:
39-
4039
- name: Get Runner User IDs
41-
ansible.builtin.getent:
42-
database: passwd
43-
key: "{{ runner_user }}"
40+
ansible.builtin.command: id -u "{{ runner_user }}"
41+
changed_when: false
42+
register: runner_user_id
4443

45-
check_mode: false
44+
- name: Get Runner Group IDs
45+
ansible.builtin.command: id -g "{{ runner_user }}"
46+
changed_when: false
47+
register: runner_user_group_id
48+
49+
- name: Set runner_system variable
50+
ansible.builtin.set_fact:
51+
runner_system: "{{ 'osx' if ansible_system == 'Darwin' else 'linux' }}"
52+
53+
- name: Find the latest runner version (RUN ONCE)
54+
ansible.builtin.uri:
55+
url: "https://api.github.com/repos/{{ runner_download_repository }}/releases/latest"
56+
headers:
57+
Content-Type: "application/json"
58+
method: GET
59+
return_content: yes
60+
status_code: 200
61+
body_format: json
62+
check_mode: false
63+
register: api_response
64+
run_once: true
65+
become: false
66+
delegate_to: localhost
67+
when: runner_version == "latest"
68+
69+
- name: Get systemd service facts
70+
ansible.builtin.service_facts:
71+
register: service_facts
72+
when: ansible_system == "Linux"

tasks/install_deps.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
- libicu72
5151
state: present
5252
update_cache: yes
53-
when: (ansible_distribution == "Debian" and ansible_distribution_release == "bookworm")
53+
when: (ansible_distribution == "Debian" and ansible_distribution_major_version == "12")
5454

5555
- name: Install dependencies on Ubuntu Xenial systems
5656
ansible.builtin.package:
@@ -91,10 +91,22 @@
9191
update_cache: yes
9292
when: (ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "20")
9393

94+
- name: Install dependencies on Ubuntu Jammy systems
95+
ansible.builtin.package:
96+
pkg:
97+
- acl
98+
- liblttng-ust1
99+
- libkrb5-3
100+
- zlib1g
101+
- libssl1.1
102+
- libicu66
103+
state: present
104+
update_cache: yes
105+
when: (ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "22")
106+
94107
- name: Install dependencies on RHEL/CentOS/Fedora systems
95108
ansible.builtin.package:
96109
name:
97-
- acl
98110
- lttng-ust
99111
- openssl-libs
100112
- krb5-libs

tasks/install_runner.yml

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,8 @@
44
path: "{{ runner_dir }}"
55
state: directory
66
mode: 0755
7-
owner: "{{ ansible_facts.getent_passwd[runner_user].1 }}"
8-
group: "{{ ansible_facts.getent_passwd[runner_user].2 }}"
9-
10-
- name: Find the latest runner version (RUN ONCE)
11-
ansible.builtin.uri:
12-
url: "https://api.github.com/repos/{{ runner_download_repository }}/releases/latest"
13-
headers:
14-
Content-Type: "application/json"
15-
method: GET
16-
return_content: yes
17-
status_code: 200
18-
body_format: json
19-
check_mode: false
20-
register: api_response
21-
run_once: true
22-
become: false
23-
delegate_to: localhost
24-
when: runner_version == "latest"
7+
owner: "{{ runner_user_id.stdout }}"
8+
group: "{{ runner_user_group_id.stdout }}"
259

2610
- name: Set runner_version variable (If latest)
2711
ansible.builtin.set_fact:
@@ -38,13 +22,14 @@
3822
- name: Unarchive runner package
3923
ansible.builtin.unarchive:
4024
src: "https://github.com/{{ runner_download_repository }}/releases/download/v{{ runner_version }}/\
41-
actions-runner-linux-{{ github_actions_architecture }}-{{ runner_version }}.tar.gz"
25+
actions-runner-{{ runner_system }}-{{ github_actions_architecture }}-{{ runner_version }}.tar.gz"
4226
dest: "{{ runner_dir }}/"
43-
owner: "{{ ansible_facts.getent_passwd[runner_user].1 }}"
44-
group: "{{ ansible_facts.getent_passwd[runner_user].2 }}"
27+
owner: "{{ runner_user_id.stdout }}"
28+
group: "{{ runner_user_group_id.stdout }}"
4529
remote_src: yes
4630
mode: 0755
47-
become: true
31+
environment:
32+
PATH: /usr/local/bin:/opt/homebrew/bin/:{{ ansible_env.HOME }}/bin:{{ ansible_env.PATH }}
4833
when: runner_version not in runner_installed.stdout or reinstall_runner
4934

5035
- name: Configure custom env file if required
@@ -87,7 +72,6 @@
8772
{{ runner_extra_config_args }}"
8873
args:
8974
chdir: "{{ runner_dir }}"
90-
become: true
9175
become_user: "{{ runner_user }}"
9276
no_log: "{{ hide_sensitive_logs | bool }}"
9377
when: runner_name not in registered_runners.json.runners|map(attribute='name')|list
@@ -106,7 +90,6 @@
10690
--replace"
10791
args:
10892
chdir: "{{ runner_dir }}"
109-
become: true
11093
become_user: "{{ runner_user }}"
11194
no_log: "{{ hide_sensitive_logs | bool }}"
11295
when: runner_name in registered_runners.json.runners|map(attribute='name')|list and reinstall_runner and not runner_org
@@ -115,32 +98,41 @@
11598
ansible.builtin.command: "./svc.sh install {{ runner_user }}"
11699
args:
117100
chdir: "{{ runner_dir }}"
101+
become: "{{ 'false' if ansible_system == 'Darwin' else 'true' }}"
118102
when: not runner_service_file_path.stat.exists
119103

120104
- name: Read service name from file
121105
ansible.builtin.slurp:
122106
src: "{{ runner_dir }}/.service"
123107
register: runner_service
124108

125-
- name: START and enable Github Actions Runner service
126-
ansible.builtin.systemd:
127-
name: "{{ runner_service.content | b64decode | replace('\n', '') }}"
128-
state: started
129-
enabled: yes
109+
- name: START and enable Github Actions Runner service # DOTO: Idempotence works only for Systemd. Need to fix for launchd.
110+
ansible.builtin.command: "./svc.sh start"
111+
args:
112+
chdir: "{{ runner_dir }}"
113+
become: "{{ 'false' if ansible_system == 'Darwin' else 'true' }}"
114+
no_log: "{{ hide_sensitive_logs | bool }}"
130115
ignore_errors: "{{ ansible_check_mode }}"
131-
when: runner_state|lower == "started"
116+
when: runner_state|lower == "started" and ansible_facts.services[(runner_service.content | b64decode) | trim ]['state'] != 'running'
132117

133118
- name: STOP and disable Github Actions Runner service
134-
ansible.builtin.systemd:
135-
name: "{{ runner_service.content | b64decode | replace('\n', '') }}"
136-
state: stopped
137-
enabled: no
119+
ansible.builtin.shell: "./svc.sh stop"
120+
args:
121+
chdir: "{{ runner_dir }}"
122+
become: "{{ 'false' if ansible_distribution == 'MacOS' else 'true' }}"
123+
no_log: "{{ hide_sensitive_logs | bool }}"
138124
ignore_errors: "{{ ansible_check_mode }}"
139125
when: runner_state|lower == "stopped"
140126

141127
- name: Version changed - RESTART Github Actions Runner service
142-
ansible.builtin.systemd:
143-
name: "{{ runner_service.content | b64decode | replace('\n', '') }}"
144-
state: restarted
128+
ansible.builtin.shell:
129+
cmd: |
130+
./svc.sh stop
131+
sleep 5
132+
./svc.sh start
133+
args:
134+
chdir: "{{ runner_dir }}"
135+
become: "{{ 'false' if ansible_system == 'Darwin' else 'true' }}"
136+
no_log: "{{ hide_sensitive_logs | bool }}"
145137
ignore_errors: "{{ ansible_check_mode }}"
146138
when: runner_version not in runner_installed.stdout and not runner_state|lower == "stopped"

tasks/uninstall_runner.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
ansible.builtin.command: "./svc.sh uninstall"
99
args:
1010
chdir: "{{ runner_dir }}"
11-
become: true
11+
become: "{{ 'false' if ansible_system == 'Darwin' else 'true' }}"
1212
when: runner_service_file_path.stat.exists
1313

1414
- name: Check GitHub Actions runner file
@@ -22,7 +22,7 @@
2222
ansible.builtin.command: "./config.sh remove --token {{ registration.json.token }} --name '{{ runner_name }}' --unattended"
2323
args:
2424
chdir: "{{ runner_dir }}"
25-
become: true
25+
become: false
2626
become_user: "{{ runner_user }}"
2727
no_log: "{{ hide_sensitive_logs | bool }}"
2828
when: runner_name in registered_runners.json.runners|map(attribute='name')|list and runner_file.stat.exists

0 commit comments

Comments
 (0)