Skip to content

Commit a284085

Browse files
committed
Merge branch 'master' into devel
2 parents b562147 + d6844c6 commit a284085

File tree

9 files changed

+83
-31
lines changed

9 files changed

+83
-31
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
push:
66
branches:
77
- master
8+
- main
89
- devel*
910

1011
jobs:

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request:
55
branches:
66
- master
7+
- main
78
- devel*
89
types: [opened, synchronize, reopened]
910
paths:

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: 11 additions & 0 deletions
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,3 +21,13 @@
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
25+
26+
- name: Check github_repo variable (RUN ONCE)
27+
ansible.builtin.assert:
28+
that:
29+
- github_repo is defined
30+
- github_repo | length > 0
31+
fail_msg: "github_repo was not found or is using an invalid format."
32+
run_once: true
33+
when: not runner_org and not github_enterprise

tasks/collect_info.yml

Lines changed: 7 additions & 2 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 github_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 github_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: github_enterprise
1419

1520
- name: Get registration token (RUN ONCE)
1621
ansible.builtin.uri:

tasks/install_deps.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- libssl1.1
1111
- libicu57
1212
state: present
13-
update_cache: yes
13+
update_cache: true
1414
when: (ansible_distribution == "Debian" and ansible_distribution_major_version == "9")
1515

1616
- name: Install dependencies on Debian Buster
@@ -23,7 +23,7 @@
2323
- libssl1.1
2424
- libicu63
2525
state: present
26-
update_cache: yes
26+
update_cache: true
2727
when: (ansible_distribution == "Debian" and ansible_distribution_major_version == "10")
2828

2929
- name: Install dependencies on Debian Bullseye
@@ -36,7 +36,7 @@
3636
- libssl1.1
3737
- libicu67
3838
state: present
39-
update_cache: yes
39+
update_cache: true
4040
when: (ansible_distribution == "Debian" and ansible_distribution_major_version == "11")
4141

4242
- name: Install dependencies on Debian Bookworm
@@ -49,7 +49,7 @@
4949
- libssl3
5050
- libicu72
5151
state: present
52-
update_cache: yes
52+
update_cache: true
5353
when: (ansible_distribution == "Debian" and ansible_distribution_major_version == "12")
5454

5555
- name: Install dependencies on Ubuntu Xenial systems
@@ -62,7 +62,7 @@
6262
- libssl1.0.0
6363
- libicu55
6464
state: present
65-
update_cache: yes
65+
update_cache: true
6666
when: (ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "16")
6767

6868
- name: Install dependencies on Ubuntu Bionic systems
@@ -75,7 +75,7 @@
7575
- libssl1.1
7676
- libicu60
7777
state: present
78-
update_cache: yes
78+
update_cache: true
7979
when: (ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "18")
8080

8181
- name: Install dependencies on Ubuntu Focal systems
@@ -88,7 +88,7 @@
8888
- libssl1.1
8989
- libicu66
9090
state: present
91-
update_cache: yes
91+
update_cache: true
9292
when: (ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "20")
9393

9494
- name: Install dependencies on Ubuntu Jammy systems
@@ -100,7 +100,7 @@
100100
- zlib1g
101101
- libicu70
102102
state: present
103-
update_cache: yes
103+
update_cache: true
104104
when: (ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "22")
105105

106106
- name: Install dependencies on RHEL/CentOS/Fedora systems
@@ -112,7 +112,7 @@
112112
- zlib
113113
- libicu
114114
state: present
115-
update_cache: yes
115+
update_cache: true
116116
when: (ansible_distribution == "RedHat") or
117117
(ansible_distribution == "CentOS") or
118118
(ansible_distribution == "Fedora") or

tasks/install_runner.yml

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
ansible.builtin.file:
44
path: "{{ runner_dir }}"
55
state: directory
6-
mode: '0755'
6+
mode: "0755"
77
owner: "{{ runner_user_id.stdout }}"
88
group: "{{ runner_user_group_id.stdout }}"
99

@@ -26,8 +26,8 @@
2626
dest: "{{ runner_dir }}/"
2727
owner: "{{ runner_user_id.stdout }}"
2828
group: "{{ runner_user_group_id.stdout }}"
29-
remote_src: yes
30-
mode: '0755'
29+
remote_src: true
30+
mode: "0755"
3131
environment:
3232
PATH: /usr/local/bin:/opt/homebrew/bin/:{{ ansible_env.HOME }}/bin:{{ ansible_env.PATH }}
3333
when: runner_version not in runner_installed.stdout or reinstall_runner
@@ -37,8 +37,8 @@
3737
path: "{{ runner_dir }}/.env"
3838
block: "{{ custom_env }}"
3939
owner: "{{ runner_user }}"
40-
create: yes
41-
mode: '0755'
40+
create: true
41+
mode: "0755"
4242
marker_begin: "# BEGIN ANSIBLE MANAGED BLOCK"
4343
marker_end: "# END ANSIBLE MANAGED BLOCK"
4444
when: custom_env is defined
@@ -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 github_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 github_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: github_enterprise
6065

6166
- name: Register runner # noqa no-changed-when
6267
environment:
@@ -72,6 +77,7 @@
7277
{{ runner_extra_config_args }}"
7378
args:
7479
chdir: "{{ runner_dir }}"
80+
changed_when: true
7581
become_user: "{{ runner_user }}"
7682
no_log: "{{ hide_sensitive_logs | bool }}"
7783
when: runner_name not in registered_runners.json.runners|map(attribute='name')|list
@@ -90,14 +96,19 @@
9096
--replace"
9197
args:
9298
chdir: "{{ runner_dir }}"
99+
changed_when: true
93100
become_user: "{{ runner_user }}"
94101
no_log: "{{ hide_sensitive_logs | bool }}"
95-
when: runner_name in registered_runners.json.runners|map(attribute='name')|list and reinstall_runner and not runner_org
102+
when: >
103+
runner_name in registered_runners.json.runners|map(attribute='name')|list and
104+
reinstall_runner and
105+
not runner_org
96106
97107
- name: Install service # noqa no-changed-when
98108
ansible.builtin.command: "./svc.sh install {{ runner_user }}"
99109
args:
100110
chdir: "{{ runner_dir }}"
111+
changed_when: true
101112
become: "{{ 'false' if ansible_system == 'Darwin' else 'true' }}"
102113
when: not runner_service_file_path.stat.exists
103114

@@ -112,10 +123,11 @@
112123
chdir: "{{ runner_dir }}"
113124
no_log: "{{ hide_sensitive_logs | bool }}"
114125
ignore_errors: "{{ ansible_check_mode }}"
115-
when:
116-
- ansible_system != 'Darwin'
117-
- runner_state|lower == "started"
118-
- ansible_facts.services[(runner_service.content | b64decode) | trim ]['state'] != 'running'
126+
changed_when: true
127+
when: >
128+
ansible_system != 'Darwin' and
129+
runner_state|lower == "started" and
130+
ansible_facts.services[(runner_service.content | b64decode) | trim ]['state'] != 'running'
119131
120132
- name: START and enable Github Actions Runner service (macOS) # TODO: Idempotence
121133
ansible.builtin.command: "./svc.sh start" # noqa no-changed-when
@@ -124,25 +136,24 @@
124136
become: false
125137
no_log: "{{ hide_sensitive_logs | bool }}"
126138
ignore_errors: "{{ ansible_check_mode }}"
139+
changed_when: true
127140
when: ansible_system == 'Darwin' and runner_state|lower
128141

129142
- name: STOP and disable Github Actions Runner service # noqa no-changed-when
130143
ansible.builtin.command: "./svc.sh stop"
131144
args:
132145
chdir: "{{ runner_dir }}"
146+
changed_when: true
133147
become: "{{ 'false' if ansible_distribution == 'MacOS' else 'true' }}"
134148
no_log: "{{ hide_sensitive_logs | bool }}"
135149
ignore_errors: "{{ ansible_check_mode }}"
136150
when: runner_state|lower == "stopped"
137151

138152
- name: Version changed - RESTART Github Actions Runner service
139-
ansible.builtin.shell: # noqa no-changed-when
140-
cmd: |
141-
./svc.sh stop
142-
sleep 5
143-
./svc.sh start
153+
ansible.builtin.command: "./svc.sh stop && sleep 5 && ./svc.sh start"
144154
args:
145155
chdir: "{{ runner_dir }}"
156+
changed_when: true
146157
become: "{{ 'false' if ansible_system == 'Darwin' else 'true' }}"
147158
no_log: "{{ hide_sensitive_logs | bool }}"
148159
ignore_errors: "{{ ansible_check_mode }}"

tasks/uninstall_runner.yml

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

@@ -25,6 +26,7 @@
2526
become: false
2627
become_user: "{{ runner_user }}"
2728
no_log: "{{ hide_sensitive_logs | bool }}"
29+
changed_when: true
2830
when: runner_name in registered_runners.json.runners|map(attribute='name')|list and runner_file.stat.exists
2931

3032
- name: Delete runner directory

0 commit comments

Comments
 (0)