Skip to content

Commit e8bbc12

Browse files
add enterprise support
1 parent a4c37f3 commit e8bbc12

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
This role will deploy/redeploy/uninstall and register/unregister local GitHub Actions Runner on Linux and macOS Systems (see [compatibility list](#supported-operating-systems) ).
12-
It supports both, Organization and Repository Runners.
12+
It supports Enterprise, Organization and Repository Runners.
1313

1414
## Requirements
1515

@@ -18,7 +18,8 @@ It supports both, Organization and Repository Runners.
1818
* The role require Personal Access Token to access the GitHub. The token can be set as `PERSONAL_ACCESS_TOKEN` environment variable.
1919

2020
> **Note**
21-
> The token must have the `repo` scope (when creating a repo runner) or the `admin:org` scope (when creating a runner for an organization).
21+
> The token must have the `repo` scope (when creating a repo runner), the `admin:org` scope (when creating a runner for an organization),
22+
> the `manage_runners:enterprise` scope (when creating a enterprise runner).
2223
Personal Access Token for GitHub account can be created [here](https://github.com/settings/tokens).
2324

2425
> **Warning**
@@ -112,6 +113,9 @@ runner_name: "{{ ansible_hostname }}"
112113
# Github repository name
113114
# github_repo: "yourrepo"
114115

116+
# GitHub Enterprise name
117+
# github_enterprise: "yourenterprise"
118+
115119
# Configuring a custom .env file
116120
# custom_env: |
117121
# http_proxy=YOUR_URL_HERE
@@ -122,7 +126,7 @@ runner_name: "{{ ansible_hostname }}"
122126
# HTTP_PROXY=
123127
```
124128

125-
## Example Playbook
129+
## Example Playbooks
126130

127131
In this example the Ansible role will install (or update) the GitHub Actions Runner service (latest available version). The runner will be registered for *my_awesome_repo* GitHub repo.
128132
Runner service will be stated and will run under the same user as the Ansible is using for ssh connection (*ansible*).
@@ -156,6 +160,20 @@ Same example as above, but runner will be added to an organization and deployed
156160
- role: monolithprojects.github_actions_runner
157161
```
158162
163+
If you have a Github Enterprise Cloud license and you want to manage all the self-hosted runners from the enterprise:
164+
```yaml
165+
---
166+
- name: Install GitHub Actions Runner
167+
hosts: all
168+
user: automation
169+
become: yes
170+
vars:
171+
- github_enterprise: my_awesome_enterprise
172+
- runner_org: no
173+
roles:
174+
- role: monolithprojects.github_actions_runner
175+
```
176+
159177
In this example the Ansible role will deploy (or update) the GitHub Actions runner service (version 2.165.2) and register the runner for the GitHub repo. Runner service will run under the user `runner-user`. Runner will be registered with two labels.
160178
The runner service will be *stopped* and disabled. Runner will use custom environment variables (from file named `.env` in the self-hosted runner application directory).
161179

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ runner_name: "{{ ansible_hostname }}"
5454
# Github repository name
5555
# github_repo: "yourrepo"
5656

57+
# GitHub Enterprise name
58+
# github_enterprise: "yourenterprise"
59+
5760
# Configuring a custom .env file
5861
# custom_env: |
5962
# http_proxy=YOUR_URL_HERE

tasks/assert.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- github_account is defined
66
fail_msg: "github_account is not defined"
77
run_once: true
8+
when: not github_enterprise
89

910
- name: Check access_token variable (RUN ONCE)
1011
ansible.builtin.assert:
@@ -20,6 +21,7 @@
2021
- runner_org | bool == True or runner_org == False
2122
fail_msg: "runner_org should be a boolean value"
2223
run_once: true
24+
when: not github_enterprise
2325

2426
- name: Check github_repo variable (RUN ONCE)
2527
ansible.builtin.assert:
@@ -28,4 +30,4 @@
2830
- github_repo | length > 0
2931
fail_msg: "github_repo was not found or is using an invalid format."
3032
run_once: true
31-
when: not runner_org
33+
when: not runner_org and not github_enterprise

tasks/collect_info.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
- name: Set complete API url for repo runner
66
ansible.builtin.set_fact:
77
github_full_api_url: "{{ github_api_url }}/repos/{{ github_owner | default(github_account) }}/{{ github_repo }}/actions/runners"
8-
when: not runner_org
8+
when: not runner_org and not runner_enterprise
99

1010
- name: Set complete API url for org runner
1111
ansible.builtin.set_fact:
1212
github_full_api_url: "{{ github_api_url }}/orgs/{{ github_owner | default(github_account) }}/actions/runners"
13-
when: runner_org | bool
13+
when: runner_org | bool and not runner_enterprise
14+
15+
- name: Set complete API url for enterprise runner
16+
ansible.builtin.set_fact:
17+
github_full_api_url: "{{ github_api_url }}/enterprises/{{ github_enterprise }}/actions/runners"
18+
when: runner_enterprise
1419

1520
- name: Get registration token (RUN ONCE)
1621
ansible.builtin.uri:
@@ -24,7 +29,7 @@
2429
register: registration
2530
run_once: true
2631

27-
- name: Check currently registered runners for repo (RUN ONCE)
32+
- name: Check currently registered runners (RUN ONCE)
2833
ansible.builtin.uri:
2934
url: "{{ github_full_api_url }}"
3035
headers:

tasks/install_runner.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,17 @@
5151
- name: Set complete GitHub url for repo runner
5252
ansible.builtin.set_fact:
5353
github_full_url: "{{ github_url }}/{{ github_owner | default(github_account) }}/{{ github_repo }}"
54-
when: not runner_org
54+
when: not runner_org and not runner_enterprise
5555

5656
- name: Set complete GitHub url for org runner
5757
ansible.builtin.set_fact:
5858
github_full_url: "{{ github_url }}/{{ github_owner | default(github_account) }}"
59-
when: runner_org | bool
59+
when: runner_org | bool and not runner_enterprise
60+
61+
- name: Set complete GitHub url for enterprise runner
62+
ansible.builtin.set_fact:
63+
github_full_url: "{{ github_url }}/enterprises/{{ github_enterprise }}"
64+
when: runner_enterprise
6065

6166
- name: Register runner
6267
environment:

0 commit comments

Comments
 (0)