Skip to content

Commit f664f82

Browse files
Merge pull request #41 from MonolithProjects/develop
- Added better way to uninstall runner - Added option to use custom name for the runner
2 parents 1ac7acb + 94616c5 commit f664f82

20 files changed

+215
-127
lines changed

.github/workflows/galaxy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
release:
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-18.04
1212
steps:
1313
- name: galaxy
1414
uses: robertdebock/[email protected]

.github/workflows/lifecycle.yml

-63
This file was deleted.

.github/workflows/lint.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: molecule lint
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- feature/*
8+
jobs:
9+
lint:
10+
runs-on: ubuntu-18.04
11+
strategy:
12+
fail-fast: true
13+
steps:
14+
- name: checkout
15+
uses: actions/checkout@v2
16+
with:
17+
path: "${{ github.repository }}"
18+
- name: Molecule for Ansible - lint
19+
uses: MonolithProjects/[email protected]
20+
with:
21+
molecule_command: lint

.github/workflows/main.yml

+16-5
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,30 @@ on:
44
push:
55
branches:
66
- master
7+
pull_request:
8+
types: [opened, synchronize, reopened]
79
schedule:
810
- cron: '0 6 * * 0'
911
jobs:
1012
test:
11-
runs-on: ubuntu-latest
13+
runs-on: ubuntu-18.04
1214
strategy:
13-
fail-fast: false
15+
fail-fast: true
1416
steps:
1517
- name: checkout
1618
uses: actions/checkout@v2
1719
with:
1820
path: "${{ github.repository }}"
19-
- name: Molecule for Ansible
20-
uses: MonolithProjects/action-molecule@v1.3.0
21+
- name: Molecule for Ansible - GHR Repository
22+
uses: MonolithProjects/action-molecule@v1.4.0
2123
env:
22-
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
24+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
25+
with:
26+
molecule_command: test
27+
- name: Molecule for Ansible - GHR Organization
28+
uses: MonolithProjects/[email protected]
29+
env:
30+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
31+
with:
32+
molecule_command: test
33+
scenario: organization

README.md

+38-20
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
[![GitHub Actions](https://github.com/MonolithProjects/ansible-github_actions_runner/workflows/molecule%20test/badge.svg?branch=master)](https://github.com/MonolithProjects/ansible-github_actions_runner/actions)
77
[![License](https://img.shields.io/github/license/MonolithProjects/ansible-github_actions_runner)](https://github.com/MonolithProjects/ansible-github_actions_runner/blob/master/LICENSE)
88

9-
This role will deploy/redeploy/uninstall and register/unregister local GitHub Actions Runner.
9+
This role will deploy/redeploy/uninstall and register/unregister local GitHub Actions Runner.
10+
It supports both, Organization and Repository Runners.
1011

1112
## Requirements
1213

@@ -26,10 +27,10 @@ Personal Access Token for GitHub account can be created [here](https://github.co
2627
* Weekly tested on:
2728
* CentOS/RHEL 7,8
2829
* Debian 9,10
29-
* Fedora 31,32
30+
* Fedora 32,33
3031
* Ubuntu 16,18,20
3132

32-
**Note:** Fedora 32 and Ubuntu 20 must use Ansible 2.9.8+. Other distros/releases will work also with older 2.8.0+ Ansible.
33+
**Note:** Fedora 32+ and Ubuntu 20 must use Ansible 2.9.8+. Other distros/releases will work also with older 2.8.0+ Ansible.
3334

3435
## Role Variables
3536

@@ -45,39 +46,45 @@ runner_dir: /opt/actions-runner
4546
# Version of the GitHub Actions Runner
4647
runner_version: "latest"
4748

48-
# If found, replace already registered runner
49-
replace_runner: yes
49+
# State in which the runner service will be after the role is done (started, stopped, absent)
50+
runner_state: "started"
5051

51-
# If found, delete already existed runner before install
52-
uninstall_runner: no
52+
# If found on the server, delete already existed runner service before install
53+
reinstall_runner: no
5354

5455
# Do not show Ansible logs which may contain sensitive data (registration token)
5556
hide_sensitive_logs: yes
5657

5758
# GitHub address
5859
github_server: "https://github.com"
5960

60-
# Personal Access Token
61+
# Personal Access Token for your GitHub account
6162
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
6263

63-
# Is it runner for organization or not
64+
# Is it the runner for organization or not
6465
runner_org: no
6566

66-
# Account used for Runner registration (GitHub Repository user with admin rights or Organization owner)
67+
# Name to assign to this runner in GitHub (hostname as default)
68+
runner_name: "{{ lookup('pipe', 'hostname') }}"
69+
70+
# GitHub Repository user or Organization owner used for Runner registration
6771
# github_account: "youruser"
6872

73+
# GitHub repository owner name (if other than github_account)
74+
# github_owner: "yourorg"
75+
6976
# Github repository name
7077
# github_repo: "yourrepo"
7178
```
7279

7380
## Example Playbook
7481

75-
In this example the Ansible role will deploy (or redeploy) the GitHub Actions runner service (latest available version) and register the runner for the GitHub repo.
76-
Runner service will run under the same user as the Ansible is using for ssh connection (*ansible*).
82+
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.
83+
Runner service will be stated and will run under the same user as the Ansible is using for ssh connection (*ansible*).
7784

7885
```yaml
7986
---
80-
- name: GitHub Actions Runner
87+
- name: Install GitHub Actions Runner
8188
hosts: all
8289
user: ansible
8390
become: yes
@@ -88,11 +95,11 @@ Runner service will run under the same user as the Ansible is using for ssh conn
8895
- role: monolithprojects.github_actions_runner
8996
```
9097
91-
Same example, but runner will be added to an organization
98+
Same example as above, but runner will be added to an organization.
9299
93100
```yaml
94101
---
95-
- name: GitHub Actions Runner
102+
- name: Install GitHub Actions Runner
96103
hosts: all
97104
user: ansible
98105
become: yes
@@ -103,26 +110,37 @@ Same example, but runner will be added to an organization
103110
- role: monolithprojects.github_actions_runner
104111
```
105112
106-
In this example the Ansible role will deploy (or redeploy) 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`.
113+
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`.
114+
The runner service will be *stopped*.
107115

108116
```yaml
109117
---
110-
- name: GitHub Actions Runner
118+
- name: Stop GitHub Actions Runner
111119
hosts: all
112120
become: yes
113121
vars:
114122
- runner_version: "2.165.2"
115123
- runner_user: runner-user
116124
- github_account: github-access-user
117125
- github_repo: my_awesome_repo
126+
- runner_state: "stopped"
118127
roles:
119128
- role: monolithprojects.github_actions_runner
120129
```
121130

122-
By using tag `uninstall` with combination of variable `uninstall_runner: yes`, GitHub Actions runner will be removed from the host and unregistered from the GitHub repository.
131+
In this example the Ansible role will uninstall the runner service and unregister it from the GitHub Repository.
123132

124-
```bash
125-
ansible-playbook playbook.yml --tags uninstall -e "uninstall_runner=yes"
133+
```yaml
134+
---
135+
- name: Uninstall GitHub Actions Runner
136+
hosts: all
137+
become: yes
138+
vars:
139+
- github_account: github-access-user
140+
- github_repo: my_awesome_repo
141+
- runner_state: "absent"
142+
roles:
143+
- role: monolithprojects.github_actions_runner
126144
```
127145

128146
## License

defaults/main.yml

+13-7
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,32 @@ runner_dir: /opt/actions-runner
88
# Version of the GitHub Actions Runner
99
runner_version: "latest"
1010

11-
# If found, replace already registered runner
12-
replace_runner: yes
11+
# State in which the runner service will be after the role is done (started, stopped, absent)
12+
runner_state: "started"
1313

14-
# If found, delete already existed runner before install
15-
uninstall_runner: no
14+
# If found on the server, delete already existed runner service before install
15+
reinstall_runner: no
1616

1717
# Do not show Ansible logs which may contain sensitive data (registration token)
18-
hide_sensitive_logs: yes
18+
hide_sensitive_logs: no
1919

2020
# GitHub address
2121
github_server: "https://github.com"
2222

2323
# Personal Access Token for your GitHub account
2424
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
2525

26-
# Is it runner for organization or not
26+
# Is it the runner for organization or not
2727
runner_org: no
2828

29+
# Name to assign to this runner in GitHub (hostname as default)
30+
runner_name: "{{ ansible_hostname }}"
31+
2932
# GitHub Repository user or Organization owner used for Runner registration
3033
# github_account: "youruser"
3134

35+
# GitHub repository owner name (if other than github_account)
36+
# github_owner: "yourorg"
37+
3238
# Github repository name
33-
# github_repo: "yourrepo"
39+
# github_repo: "yourrepo"

molecule/default/cleanup.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
- name: Cleanup
3+
user: ansible
4+
hosts: all
5+
become: yes
6+
vars:
7+
- runner_user: ansible
8+
- github_repo: ansible-github_actions_runner-testrepo
9+
- github_account: monolithprojects
10+
- runner_state: absent
11+
roles:
12+
- ansible-github_actions_runner

molecule/default/converge.yml

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
---
2-
- name: Converge
2+
- name: Install
33
user: ansible
44
hosts: all
55
become: yes
66
vars:
77
- runner_user: ansible
88
- github_repo: ansible-github_actions_runner-testrepo
99
- github_account: monolithprojects
10+
- runner_version: "latest"
11+
roles:
12+
- robertdebock.epel
13+
- ansible-github_actions_runner
14+
15+
- name: Reinstall
16+
user: ansible
17+
hosts: all
18+
become: yes
19+
vars:
20+
- runner_user: ansible
21+
- github_repo: ansible-github_actions_runner-testrepo
22+
- github_account: monolithprojects
23+
- reinstall_runner: yes
24+
- runner_version: "latest"
1025
roles:
1126
- robertdebock.epel
1227
- ansible-github_actions_runner

0 commit comments

Comments
 (0)