Skip to content

Commit 34923d0

Browse files
Merge pull request #59 from MonolithProjects/develop
Add option to change the service name
2 parents bfac715 + 23e72bf commit 34923d0

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ reinstall_runner: no
6666
hide_sensitive_logs: yes
6767

6868
# GitHub address
69-
github_server: "https://github.com"
69+
github_url: "https://github.com"
70+
71+
# GitHub API
72+
github_api_url: "https://api.github.com"
7073

7174
# Personal Access Token for your GitHub account
7275
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
@@ -77,6 +80,9 @@ runner_org: no
7780
# Name to assign to this runner in GitHub (System hostname as default)
7881
runner_name: "{{ ansible_hostname }}"
7982

83+
# Custom service name when usign Github Enterprise server
84+
# service_name: actions.runner._services.{{ runner_name }}.service
85+
8086
# GitHub Repository user or Organization owner used for Runner registration
8187
# github_account: "youruser"
8288

defaults/main.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ reinstall_runner: no
2121
hide_sensitive_logs: yes
2222

2323
# GitHub address
24-
github_server: "https://github.com"
24+
github_url: "https://github.com"
25+
26+
# GitHub API
27+
github_api_url: "https://api.github.com"
2528

2629
# Personal Access Token for your GitHub account
2730
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
@@ -32,6 +35,9 @@ runner_org: no
3235
# Name to assign to this runner in GitHub (System hostname as default)
3336
runner_name: "{{ ansible_hostname }}"
3437

38+
# Custom service name when usign Github Enterprise server
39+
# service_name: actions.runner._services.{{ runner_name }}.service
40+
3541
# GitHub Repository user or Organization owner used for Runner registration
3642
# github_account: "youruser"
3743

tasks/collect_info_org.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
- name: Get registration token (RUN ONCE)
33
uri:
4-
url: "https://api.github.com/orgs/{{ github_owner | default(github_account) }}/actions/runners/registration-token"
4+
url: "{{ github_api_url }}/orgs/{{ github_owner | default(github_account) }}/actions/runners/registration-token"
55
headers:
66
Authorization: "token {{ access_token }}"
77
Accept: "application/vnd.github.v3+json"
@@ -16,7 +16,7 @@
1616

1717
- name: Check currently registered runners (RUN ONCE)
1818
uri:
19-
url: "https://api.github.com/orgs/{{ github_owner | default(github_account) }}/actions/runners"
19+
url: "{{ github_api_url }}/orgs/{{ github_owner | default(github_account) }}/actions/runners"
2020
headers:
2121
Authorization: "token {{ access_token }}"
2222
Accept: "application/vnd.github.v3+json"
@@ -38,6 +38,15 @@
3838
- name: Build service name
3939
set_fact:
4040
runner_service: "actions.runner.{{ (github_owner | default(github_account))[:45] }}.{{ runner_name }}.service"
41+
when: service_name is not defined
42+
tags:
43+
- install
44+
- uninstall
45+
46+
- name: Build service name
47+
set_fact:
48+
runner_service: "{{ service_name }}"
49+
when: service_name is defined
4150
tags:
4251
- install
4352
- uninstall

tasks/collect_info_repo.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
- name: Get registration token (RUN ONCE)
33
uri:
4-
url: "https://api.github.com/repos/{{ github_owner | default(github_account) }}/{{ github_repo }}/actions/runners/registration-token"
4+
url: "{{ github_api_url }}/repos/{{ github_owner | default(github_account) }}/{{ github_repo }}/actions/runners/registration-token"
55
headers:
66
Authorization: "token {{ access_token }}"
77
Accept: "application/vnd.github.v3+json"
@@ -16,7 +16,7 @@
1616

1717
- name: Check currently registered runners (RUN ONCE)
1818
uri:
19-
url: "https://api.github.com/repos/{{ github_owner | default(github_account) }}/{{ github_repo }}/actions/runners"
19+
url: "{{ github_api_url }}/repos/{{ github_owner | default(github_account) }}/{{ github_repo }}/actions/runners"
2020
headers:
2121
Authorization: "token {{ access_token }}"
2222
Accept: "application/vnd.github.v3+json"
@@ -45,6 +45,15 @@
4545
- name: Build service name
4646
set_fact:
4747
runner_service: "actions.runner.{{ svc_name[:45] }}.{{ runner_name }}.service"
48+
when: service_name is not defined
49+
tags:
50+
- install
51+
- uninstall
52+
53+
- name: Build service name
54+
set_fact:
55+
runner_service: "{{ service_name }}"
56+
when: service_name is defined
4857
tags:
4958
- install
5059
- uninstall

tasks/install_runner.yml

+5-7
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
uri:
1515
url: "https://api.github.com/repos/actions/runner/releases/latest"
1616
headers:
17-
Authorization: "token {{ access_token }}"
18-
Accept: "application/vnd.github.v3+json"
17+
Content-Type: "application/json"
1918
method: GET
20-
force_basic_auth: yes
2119
return_content: yes
2220
status_code: 200
2321
body_format: json
@@ -81,7 +79,7 @@
8179
- install
8280

8381
- name: Register runner (if new installation) for repo
84-
command: "{{ runner_dir }}/./config.sh --url {{ github_server }}/{{ github_owner | default(github_account) }}/{{ github_repo }} \
82+
command: "{{ runner_dir }}/./config.sh --url {{ github_url }}/{{ github_owner | default(github_account) }}/{{ github_repo }} \
8583
--token {{ registration.json.token }} --name {{ runner_name }} --unattended"
8684
args:
8785
chdir: "{{ runner_dir }}"
@@ -93,7 +91,7 @@
9391
- install
9492

9593
- name: Register runner (if new installation) for organization
96-
command: "{{ runner_dir }}/./config.sh --url {{ github_server }}/{{ github_owner | default(github_account) }} \
94+
command: "{{ runner_dir }}/./config.sh --url {{ github_url }}/{{ github_owner | default(github_account) }} \
9795
--token {{ registration.json.token }} --name {{ runner_name }} --unattended"
9896
args:
9997
chdir: "{{ runner_dir }}"
@@ -105,7 +103,7 @@
105103
- install
106104

107105
- name: Replace registered runner for repo
108-
command: "{{ runner_dir }}/config.sh --url {{ github_server }}/{{ github_owner | default(github_account) }}/{{ github_repo }} \
106+
command: "{{ runner_dir }}/config.sh --url {{ github_url }}/{{ github_owner | default(github_account) }}/{{ github_repo }} \
109107
--token {{ registration.json.token }} --name {{ runner_name }} --unattended --replace"
110108
args:
111109
chdir: "{{ runner_dir }}"
@@ -117,7 +115,7 @@
117115
- install
118116

119117
- name: Replace registered runner for organization
120-
command: "{{ runner_dir }}/config.sh --url {{ github_server }}/{{ github_owner | default(github_account) }} \
118+
command: "{{ runner_dir }}/config.sh --url {{ github_url }}/{{ github_owner | default(github_account) }} \
121119
--token {{ registration.json.token }} --name {{ runner_name }} --unattended --replace"
122120
args:
123121
chdir: "{{ runner_dir }}"

0 commit comments

Comments
 (0)