Skip to content

Commit 9f22136

Browse files
Merge pull request #11 from MonolithProjects/develop
Fix reinstallation Former-commit-id: 2782e9f
2 parents 2a165f2 + a1430cb commit 9f22136

File tree

7 files changed

+44
-28
lines changed

7 files changed

+44
-28
lines changed

README.md

+29-15
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
GitHub Actions Runner
2-
=========
1+
# GitHub Actions Runner
32

43
[![Galaxy Quality](https://img.shields.io/ansible/quality/47375?style=flat&logo=ansible)](https://galaxy.ansible.com/monolithprojects/github_actions_runner)
54
[![Role version](https://img.shields.io/github/v/release/MonolithProjects/ansible-github_actions_runner)](https://galaxy.ansible.com/monolithprojects/github_actions_runner)
65
[![Role downloads](https://img.shields.io/ansible/role/d/47375)](https://galaxy.ansible.com/monolithprojects/github_actions_runner)
76
[![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)
87
[![License](https://img.shields.io/github/license/MonolithProjects/ansible-github_actions_runner)](https://github.com/MonolithProjects/ansible-github_actions_runner/blob/master/LICENSE)
98

10-
This role will deploy or redeploy or uninstall and register or unregister local GitHub Actions Runner (version you specified).
9+
This role will deploy or redeploy or uninstall and register or unregister local GitHub Actions Runner.
1110

12-
Requirements
13-
------------
11+
## Requirements
1412

1513
* Supported Linux distros:
1614
* CentOS/RHEL 7,8
@@ -20,23 +18,24 @@ Requirements
2018

2119
* System must have access to the GitHub.
2220

21+
* The role require Personal Access Token for the GitHub user. The token has to be a value of `PERSONAL_ACCESS_TOKEN` variable.
22+
Export the token to the local host environment. The token has to have admin rights for the repo.
23+
Personal Access Token for GitHub account can be created [here](https://github.com/settings/tokens).
24+
**Note:** Never store you personal access token in the GitHub repository. Use [GitHub Secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) or some different secrets service.
25+
2326
* Runner user has to be pre-created.
2427
Recommended role: `monolithprojects.user_management`
2528

2629
* CentOS/Fedora systems require EPEL repository.
2730
Recommended role: `robertdebock.epel`
2831

29-
* `PERSONAL_ACCESS_TOKEN` variable needs to be exported to your environment. The token has to have admin rights for the repo.
30-
Personal Access Token for your GitHub account can be created [here](https://github.com/settings/tokens).
31-
32-
Role Variables
33-
--------------
32+
## Role Variables
3433

3534
This is a copy from `defaults/main.yml`
3635

3736
```yaml
3837
# Runner user - user under which is the local runner service running
39-
runner_user: runner
38+
runner_user: "{{ lookup('env','USER') }}"
4039

4140
# Directory where the local runner will be installed
4241
runner_dir: /opt/actions-runner
@@ -63,8 +62,23 @@ github_server: "https://github.com"
6362
# github_repo: "yourrepo"
6463
```
6564

66-
Example Playbook
67-
----------------
65+
## Example Playbook
66+
67+
In this example the role will deploy (or redeploy) the GitHub Actions runner service (latest available version) and register the runner for the GitHub repo.
68+
Runner service will run under the same user as the Ansible is using for ssh connection (*ansible*).
69+
70+
```yaml
71+
---
72+
- name: GitHub Actions Runner
73+
hosts: all
74+
user: ansible
75+
become: yes
76+
vars:
77+
- github_account: my-github-user
78+
- github_repo: my_awesome_repo
79+
roles:
80+
- role: monolithprojects.github_actions_runner
81+
```
6882
6983
In this example the role will deploy (or redeploy) the GitHub Actions runner service (version 2.165.2) and register the runner for the GitHub repo.
7084
@@ -75,8 +89,8 @@ In this example the role will deploy (or redeploy) the GitHub Actions runner ser
7589
become: yes
7690
vars:
7791
- runner_version: "2.165.2"
78-
- runner_user: ansible
79-
- github_account: myuser
92+
- runner_user: runner-user
93+
- github_account: my-github-user
8094
- github_repo: my_awesome_repo
8195
roles:
8296
- role: monolithprojects.github_actions_runner

defaults/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
# Runner user - user under which is the local runner service running
3-
runner_user: runner
3+
runner_user: "{{ lookup('env','USER') }}"
44

55
# Directory where the local runner will be installed
66
runner_dir: /opt/actions-runner

meta/main.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@
3030
- runner
3131
- cicd
3232
dependencies:
33-
- robertdebock.epel
33+
- robertdebock.epel
34+
- monolithprojects.user_management

molecule/default/converge.yml

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
hosts: all
55
become: yes
66
vars:
7-
- runner_version: "2.168.0"
87
- runner_user: ansible
98
- github_repo: ansible-github_actions_runner-testrepo
109
- github_account: monolithprojects

molecule/default/requirements.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
---
22
- role: robertdebock.epel
3+
version: master
4+
- role: monolithprojects.user_management
35
version: master

tasks/install_runner.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
tags:
1111
- install
1212

13-
- name: Find the latest runner version
13+
- name: Find the latest runner version (RUN ONCE)
1414
uri:
1515
url: "https://api.github.com/repos/actions/runner/releases/latest"
1616
url_username: "{{ github_account }}"
@@ -32,7 +32,7 @@
3232
runner_version: "{{ api_response.json.tag_name | regex_replace('^v', '') }}"
3333
when: runner_version == "latest"
3434

35-
- name: Download runner package version - "{{ runner_version }}"
35+
- name: Download runner package version - "{{ runner_version }}" (RUN ONCE)
3636
get_url:
3737
url: "https://github.com/actions/runner/releases/download/v{{ runner_version }}/actions-runner-linux-x64-{{ runner_version }}.tar.gz"
3838
dest: "./actions-runner-linux-{{ runner_version }}.tar.gz"
@@ -57,7 +57,7 @@
5757
chdir: "{{ runner_dir }}"
5858
become: yes
5959
become_user: "{{ runner_user }}"
60-
no_log: "{{ hide_sensitive_logs }}"
60+
no_log: "{{ hide_sensitive_logs | bool }}"
6161
when: ansible_hostname not in registered_runners.json.runners|map(attribute='name')|list
6262
tags:
6363
- install
@@ -69,7 +69,7 @@
6969
chdir: "{{ runner_dir }}"
7070
become: yes
7171
become_user: "{{ runner_user }}"
72-
no_log: "{{ hide_sensitive_logs }}"
72+
no_log: "{{ hide_sensitive_logs | bool }}"
7373
when: replace_runner and ansible_hostname in registered_runners.json.runners|map(attribute='name')|list
7474
tags:
7575
- install

tasks/uninstall_runner.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
tags:
99
- uninstall
1010

11-
- name: Refresh services facts
12-
service_facts:
13-
tags:
14-
- uninstall
15-
1611
- name: Remove GitHub Actions Runner service
1712
file:
1813
path: "{{ item }}"
@@ -29,6 +24,11 @@
2924
tags:
3025
- uninstall
3126

27+
- name: Refresh services facts
28+
service_facts:
29+
tags:
30+
- uninstall
31+
3232
- name: Check GitHub Actions runner file
3333
stat:
3434
path: "{{ runner_dir }}/.runner"
@@ -42,7 +42,7 @@
4242
chdir: "{{ runner_dir }}"
4343
become: yes
4444
become_user: "{{ runner_user }}"
45-
no_log: "{{ hide_sensitive_logs }}"
45+
no_log: "{{ hide_sensitive_logs | bool }}"
4646
when: ansible_hostname in registered_runners.json.runners|map(attribute='name')|list and runner_file.stat.exists
4747
tags:
4848
- uninstall

0 commit comments

Comments
 (0)