Skip to content

Commit b038a6a

Browse files
Merge pull request #222 from MonolithProjects/develop
Develop to Master
2 parents 75ae9e5 + fcb74e4 commit b038a6a

12 files changed

+275
-37
lines changed

.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
SUITE: default
1717
steps:
1818
- name: Check out the codebase.
19-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
2020
with:
2121
path: ${{ env.ANSIBLE_ROLE }}
2222

.github/workflows/tests.yml

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ name: molecule test
22

33
on:
44
push:
5-
branches:
6-
- develop
7-
pull_request:
85
branches:
96
- master
10-
- main
11-
types: [opened, synchronize, reopened]
7+
- develop
128
paths:
139
- 'defaults/**'
1410
- 'handlers/**'
@@ -86,7 +82,7 @@ jobs:
8682
- os: "rockylinux9"
8783
steps:
8884
- name: checkout
89-
uses: actions/checkout@v3
85+
uses: actions/checkout@v4
9086
with:
9187
path: "${{ github.repository }}"
9288

README.md

+26-14
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@
1010
This role will deploy/redeploy/uninstall and register/unregister local GitHub Actions Runner on Linux and macOS Systems (see [compatibility list](#supported-operating-systems) ).
1111
It supports Enterprise, Organization and Repository Runners.
1212

13-
## Role Installation
14-
15-
**requirements.yml**
16-
```yml
17-
roles:
18-
- name: monolithprojects.github_actions_runner
19-
version: 1.21.1
20-
src: https://github.com/MonolithProjects/ansible-github_actions_runner
21-
```
13+
> [!IMPORTANT]
14+
> My Galaxy account is currently broken. Please use Github for installation source.
15+
>
16+
> **CLI:**
17+
>
18+
>```yml
19+
>ansible-galaxy role install git+https://github.com/MonolithProjects/ansible-github_actions_runner.git,1.21.1
20+
>```
21+
>
22+
>**requirements.yml:**
23+
>
24+
>```yml
25+
>roles:
26+
> - name: monolithprojects.github_actions_runner
27+
> version: 1.21.1
28+
> src: https://github.com/MonolithProjects/ansible-github_actions_runner
29+
>```
2230
2331
## Requirements
2432
@@ -47,13 +55,14 @@ Personal Access Token for GitHub account can be created [here](https://github.co
4755
4856
## Supported Operating Systems
4957
50-
* Red Hat Enterprise Linux 7
51-
* CentOS 7
58+
* Red Hat Enterprise Linux 7+
59+
* CentOS 7+
5260
* Rocky Linux 8+
5361
* Fedora 29+
5462
* Debian 9+
55-
* Ubuntu 16.04+
63+
* Ubuntu 18.04+
5664
* MacOS High Sierra +
65+
* Windows
5766
5867
## Weekly tested on:
5968
@@ -72,7 +81,7 @@ This is a copy from `defaults/main.yml`
7281
runner_user: "{{ lookup('env', 'USER') }}"
7382
7483
# Directory where the local runner will be installed
75-
runner_dir: /opt/actions-runner
84+
runner_dir: "{{ 'C:\\actions-runner' if ansible_facts.system == 'Win32NT' else '/opt/actions-runner' }}"
7685
7786
# Version of the GitHub Actions Runner
7887
runner_version: "latest"
@@ -111,7 +120,7 @@ runner_group: ""
111120
runner_download_repository: "actions/runner"
112121
113122
# Extra arguments to pass to `config.sh`.
114-
# Several arguments muste be set as one string (i.e. "--ephemeral --my_special_fork")
123+
# Several arguments must be set as one string (i.e. "--ephemeral --my_special_fork")
115124
runner_extra_config_args: ""
116125
117126
# Name to assign to this runner in GitHub (System hostname as default)
@@ -132,6 +141,9 @@ all_runners_in_same_repo: true
132141
# GitHub Enterprise name
133142
# github_enterprise: "yourenterprise"
134143
144+
# Runner user Windows password - the logon password for the service user when running on windows.
145+
# runner_user_win_password: "{{ lookup('env', 'PASS') }}"
146+
135147
# Configuring a custom .env file
136148
# custom_env: |
137149
# http_proxy=YOUR_URL_HERE

defaults/main.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
runner_user: "{{ lookup('env', 'USER') }}"
44

55
# Directory where the local runner will be installed
6-
runner_dir: /opt/actions-runner
6+
runner_dir: "{{ 'C:\\actions-runner' if ansible_facts.system == 'Win32NT' else '/opt/actions-runner' }}"
77

88
# Version of the GitHub Actions Runner
99
runner_version: "latest"
@@ -42,7 +42,7 @@ runner_group: ""
4242
runner_download_repository: "actions/runner"
4343

4444
# Extra arguments to pass to `config.sh`.
45-
# Several arguments muste be set as one string (i.e. "--ephemeral --my_special_fork")
45+
# Several arguments must be set as one string (i.e. "--ephemeral --my_special_fork")
4646
runner_extra_config_args: ""
4747

4848
# Name to assign to this runner in GitHub (System hostname as default)
@@ -63,6 +63,9 @@ all_runners_in_same_repo: true
6363
# GitHub Enterprise name
6464
# github_enterprise: "yourenterprise"
6565

66+
# Runner user Windows password - the logon password for the service user when running on windows.
67+
# runner_user_win_password: "{{ lookup('env', 'PASS') }}"
68+
6669
# Configuring a custom .env file
6770
# custom_env: |
6871
# http_proxy=YOUR_URL_HERE

tasks/assert.yml

+8
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@
3131
fail_msg: "github_repo was not found or is using an invalid format."
3232
run_once: true
3333
when: not runner_org and github_enterprise is not defined
34+
35+
- name: Check runner_user_win_password (RUN ONCE)
36+
ansible.builtin.assert:
37+
that:
38+
- runner_user_win_password is defined
39+
fail_msg: "runner_user_win_password was not defined, but it is required on a windows system"
40+
run_once: true
41+
when: github_actions_system == "win"

tasks/collect_info.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
status_code: 201
2828
force_basic_auth: true
2929
register: registration
30+
delegate_to: localhost
31+
become: false
3032
run_once: true
3133

3234
- name: "Check currently registered runners for repo {{ '(RUN ONCE)' if all_runners_in_same_repo else '' }}"
@@ -42,21 +44,21 @@
4244
status_code: 200
4345
force_basic_auth: true
4446
register: registered_runners
47+
delegate_to: localhost
48+
become: false
4549
run_once: "{{ all_runners_in_same_repo }}"
4650

4751
- name: Get Runner User IDs
4852
ansible.builtin.command: id -u "{{ runner_user }}"
4953
changed_when: false
5054
register: runner_user_id
55+
when: github_actions_system != "win"
5156

5257
- name: Get Runner Group IDs
5358
ansible.builtin.command: id -g "{{ runner_user }}"
5459
changed_when: false
5560
register: runner_user_group_id
56-
57-
- name: Set runner_system variable
58-
ansible.builtin.set_fact:
59-
runner_system: "{{ 'osx' if ansible_facts.system == 'Darwin' else 'linux' }}"
61+
when: github_actions_system != "win"
6062

6163
- name: Find the latest runner version (RUN ONCE)
6264
ansible.builtin.uri:
@@ -77,4 +79,4 @@
7779
- name: Get systemd service facts
7880
ansible.builtin.service_facts:
7981
register: service_facts
80-
when: ansible_facts.system == "Linux"
82+
when: github_actions_system == "linux"

tasks/install_runner.yml tasks/install_runner_unix.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
- name: Unarchive runner package
2323
ansible.builtin.unarchive:
2424
src: "https://github.com/{{ runner_download_repository }}/releases/download/v{{ runner_version }}/\
25-
actions-runner-{{ runner_system }}-{{ github_actions_architecture }}-{{ runner_version }}.tar.gz"
25+
actions-runner-{{ github_actions_system }}-{{ github_actions_architecture }}-{{ runner_version }}.tar.gz"
2626
dest: "{{ runner_dir }}/"
2727
owner: "{{ runner_user_id.stdout }}"
2828
group: "{{ runner_user_group_id.stdout }}"

tasks/install_runner_win.yml

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
---
2+
- name: Create directory
3+
ansible.windows.win_file:
4+
path: "{{ runner_dir }}"
5+
state: directory
6+
7+
- name: Set owner of directory
8+
ansible.windows.win_owner:
9+
path: "{{ runner_dir }}"
10+
user: "{{ runner_user }}"
11+
12+
- name: Set runner_version variable (If latest)
13+
ansible.builtin.set_fact:
14+
runner_version: "{{ api_response.json.tag_name | regex_replace('^v', '') }}"
15+
when: runner_version == "latest"
16+
17+
- name: Check if desired version already installed
18+
ansible.windows.win_command: "grep -i {{ runner_version }} {{ runner_dir }}\\bin\\Runner.Listener.deps.json"
19+
register: runner_installed
20+
check_mode: false
21+
changed_when: false
22+
ignore_errors: true
23+
24+
- name: Download runner package
25+
ansible.windows.win_get_url:
26+
url: "https://github.com/{{ runner_download_repository }}/releases/download/v{{ runner_version }}/\
27+
actions-runner-{{ github_actions_system }}-{{ github_actions_architecture }}-{{ runner_version }}.zip"
28+
dest: "%TEMP%\\actions-runner-{{ github_actions_system }}-{{ github_actions_architecture }}-{{ runner_version }}.zip"
29+
when: runner_version not in runner_installed.stdout or reinstall_runner
30+
31+
- name: Unarchive runner package
32+
community.windows.win_unzip:
33+
src: "%TEMP%\\actions-runner-{{ github_actions_system }}-{{ github_actions_architecture }}-{{ runner_version }}.zip"
34+
dest: "{{ runner_dir }}\\"
35+
delete_archive: yes
36+
when: runner_version not in runner_installed.stdout or reinstall_runner
37+
38+
- name: Configure custom env file if required
39+
randrej.windows.win_blockinfile:
40+
path: "{{ runner_dir }}\\.env"
41+
block: "{{ custom_env }}"
42+
create: true
43+
marker: "# {mark} ANSIBLE MANAGED BLOCK"
44+
marker_begin: BEGIN
45+
marker_end: END
46+
when: custom_env is defined
47+
48+
- name: Check if runner service name file exist
49+
ansible.windows.win_stat:
50+
path: "{{ runner_dir }}/.service"
51+
register: runner_service_file_path
52+
53+
- name: Set complete GitHub url for repo runner
54+
ansible.builtin.set_fact:
55+
github_full_url: "{{ github_url }}/{{ github_owner | default(github_account) }}/{{ github_repo }}"
56+
when: not runner_org and github_enterprise is not defined
57+
58+
- name: Set complete GitHub url for org runner
59+
ansible.builtin.set_fact:
60+
github_full_url: "{{ github_url }}/{{ github_owner | default(github_account) }}"
61+
when: runner_org | bool and github_enterprise is not defined
62+
63+
- name: Set complete GitHub url for enterprise runner
64+
ansible.builtin.set_fact:
65+
github_full_url: "{{ github_url }}/enterprises/{{ github_enterprise }}"
66+
when: github_enterprise is defined
67+
68+
- name: Register runner # noqa no-changed-when
69+
environment:
70+
RUNNER_ALLOW_RUNASROOT: "1"
71+
ansible.windows.win_command:
72+
"{{ runner_dir }}\\config.cmd \
73+
--url {{ github_full_url }} \
74+
--token {{ registration.json.token }} \
75+
--name {{ runner_name }} \
76+
--labels {{ runner_labels | join(',') }} \
77+
--runnergroup {{ runner_group }} \
78+
--runasservice \
79+
--windowslogonaccount {{ runner_user }} \
80+
--windowslogonpassword {{ runner_user_win_password }} \
81+
--unattended \
82+
{{ runner_extra_config_args }}"
83+
args:
84+
chdir: "{{ runner_dir }}"
85+
changed_when: true
86+
become_method: ansible.builtin.runas
87+
become_user: "{{ runner_user }}"
88+
become: true
89+
no_log: "{{ hide_sensitive_logs | bool }}"
90+
when: runner_name not in registered_runners.json.runners|map(attribute='name')|list
91+
92+
- name: Replace registered runner # noqa no-changed-when
93+
environment:
94+
RUNNER_ALLOW_RUNASROOT: "1"
95+
ansible.windows.win_command:
96+
"{{ runner_dir }}\\config.cmd \
97+
--url {{ github_full_url }} \
98+
--token {{ registration.json.token }} \
99+
--name {{ runner_name }} \
100+
--labels {{ runner_labels | join(',') }} \
101+
--runasservice \
102+
--windowslogonaccount {{ runner_user }} \
103+
--windowslogonpassword {{ runner_user_win_password }} \
104+
--unattended \
105+
{{ runner_extra_config_args }} \
106+
--replace"
107+
args:
108+
chdir: "{{ runner_dir }}"
109+
changed_when: true
110+
become_method: ansible.builtin.runas
111+
become_user: "{{ runner_user }}"
112+
become: true
113+
no_log: "{{ hide_sensitive_logs | bool }}"
114+
when: >
115+
runner_name in registered_runners.json.runners|map(attribute='name')|list and
116+
reinstall_runner
117+
118+
- name: Read service name from file
119+
ansible.windows.win_command: "cat {{ runner_dir }}\\.service"
120+
register: runner_service
121+
changed_when: false
122+
123+
- name: START and enable Github Actions Runner service
124+
ansible.windows.win_service:
125+
name: "{{ runner_service.stdout }}"
126+
start_mode: auto
127+
state: started
128+
when: runner_state|lower == "started"
129+
130+
- name: STOP and disable Github Actions Runner service
131+
ansible.windows.win_service:
132+
name: "{{ runner_service.stdout }}"
133+
start_mode: manual
134+
state: stopped
135+
when: runner_state|lower == "stopped"
136+
137+
- name: Version changed - RESTART Github Actions Runner service
138+
ansible.windows.win_service:
139+
name: "{{ runner_service.stdout }}"
140+
start_mode: auto
141+
state: restarted
142+
when: runner_version not in runner_installed.stdout and not runner_state|lower == "stopped"

0 commit comments

Comments
 (0)