Skip to content

Commit 97b20e7

Browse files
Merge pull request #26 from MonolithProjects/develop
Change GitHub API authentication method
2 parents 8f14b1d + 7bcc7cd commit 97b20e7

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- master
77
- develop
8+
- feature/*
89
schedule:
910
- cron: '0 6 * * 0'
1011
jobs:

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This role will deploy/redeploy/uninstall and register/unregister local GitHub Ac
1212

1313
* System must have access to the GitHub.
1414

15-
* The role require Personal Access Token for the GitHub user. The token has to be a value of `PERSONAL_ACCESS_TOKEN` variable.
15+
* The role require Personal Access Token to access the GitHub. The token has to be a value of `PERSONAL_ACCESS_TOKEN` variable.
1616
Export the token to the local host environment. The token has to have admin rights for the repo.
1717
Personal Access Token for GitHub account can be created [here](https://github.com/settings/tokens).
1818
**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.
@@ -51,13 +51,13 @@ replace_runner: yes
5151
# Do not show Ansible logs which may contain sensitive data (registration token)
5252
hide_sensitive_logs: yes
5353

54-
# Personal Access Token for your GitHub account
55-
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
56-
5754
# GitHub address
5855
github_server: "https://github.com"
5956

60-
# GitHub account name
57+
# Personal Access Token
58+
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
59+
60+
# Account used for Runner registration (GitHub Repository user with admin rights or Organization owner)
6161
# github_account: "youruser"
6262

6363
# Github repository name
@@ -66,7 +66,7 @@ github_server: "https://github.com"
6666

6767
## Example Playbook
6868

69-
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.
69+
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.
7070
Runner service will run under the same user as the Ansible is using for ssh connection (*ansible*).
7171

7272
```yaml
@@ -76,13 +76,13 @@ Runner service will run under the same user as the Ansible is using for ssh conn
7676
user: ansible
7777
become: yes
7878
vars:
79-
- github_account: my-github-user
79+
- github_account: github-access-user
8080
- github_repo: my_awesome_repo
8181
roles:
8282
- role: monolithprojects.github_actions_runner
8383
```
8484
85-
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. Runner service will run under the used `runner-user`.
85+
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`.
8686

8787
```yaml
8888
---
@@ -92,7 +92,7 @@ In this example the role will deploy (or redeploy) the GitHub Actions runner ser
9292
vars:
9393
- runner_version: "2.165.2"
9494
- runner_user: runner-user
95-
- github_account: my-github-user
95+
- github_account: github-access-user
9696
- github_repo: my_awesome_repo
9797
roles:
9898
- role: monolithprojects.github_actions_runner
@@ -104,12 +104,10 @@ By using tag `uninstall`, GitHub Actions runner will be removed from the host an
104104
ansible-playbook playbook.yml --tags uninstall
105105
```
106106

107-
License
108-
-------
107+
## License
109108

110109
MIT
111110

112-
Author Information
113-
------------------
111+
## Author Information
114112

115113
Created in 2020 by Michal Muransky

defaults/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ replace_runner: yes
1414
# Do not show Ansible logs which may contain sensitive data (registration token)
1515
hide_sensitive_logs: yes
1616

17-
# Personal Access Token for your GitHub account
18-
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
19-
2017
# GitHub address
2118
github_server: "https://github.com"
2219

23-
# GitHub account name
20+
# Personal Access Token for your GitHub account
21+
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
22+
23+
# GitHub Repository user or Organization owner used for Runner registration
2424
# github_account: "youruser"
2525

2626
# Github repository name

tasks/collect_info.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
- name: Get registration token (RUN ONCE)
33
uri:
44
url: "https://api.github.com/repos/{{ github_account }}/{{ github_repo }}/actions/runners/registration-token"
5-
user: "{{ github_account }}"
6-
password: "{{ access_token }}"
5+
headers:
6+
Authorization: "token {{ access_token }}"
7+
Accept: "application/vnd.github.v3+json"
78
method: POST
89
status_code: 201
910
force_basic_auth: yes
@@ -16,8 +17,9 @@
1617
- name: Check currently registered runners (RUN ONCE)
1718
uri:
1819
url: "https://api.github.com/repos/{{ github_account }}/{{ github_repo }}/actions/runners"
19-
user: "{{ github_account }}"
20-
password: "{{ access_token }}"
20+
headers:
21+
Authorization: "token {{ access_token }}"
22+
Accept: "application/vnd.github.v3+json"
2123
method: GET
2224
status_code: 200
2325
force_basic_auth: yes
@@ -35,7 +37,7 @@
3537

3638
- name: Combine Github account and repo names
3739
set_fact:
38-
svc_name: "{{ github_account }}-{{ github_repo }}"
40+
svc_name: "{{ github_owner | default(github_account) }}-{{ github_repo }}"
3941
tags:
4042
- install
4143
- uninstall

tasks/install_runner.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
- name: Find the latest runner version (RUN ONCE)
1414
uri:
1515
url: "https://api.github.com/repos/actions/runner/releases/latest"
16-
url_username: "{{ github_account }}"
17-
url_password: "{{ access_token }}"
16+
headers:
17+
Authorization: "token {{ access_token }}"
18+
Accept: "application/vnd.github.v3+json"
1819
method: GET
1920
force_basic_auth: yes
2021
return_content: yes
@@ -51,7 +52,7 @@
5152
- install
5253

5354
- name: Register runner (if new installation)
54-
command: "{{ runner_dir }}/./config.sh --url {{ github_server }}/{{ github_account }}/{{ github_repo }} \
55+
command: "{{ runner_dir }}/./config.sh --url {{ github_server }}/{{ github_owner | default(github_account) }}/{{ github_repo }} \
5556
--token {{ registration.json.token }} --unattended"
5657
args:
5758
chdir: "{{ runner_dir }}"
@@ -63,7 +64,7 @@
6364
- install
6465

6566
- name: Replace registered runner
66-
command: "{{ runner_dir }}/config.sh --url {{ github_server }}/{{ github_account }}/{{ github_repo }} \
67+
command: "{{ runner_dir }}/config.sh --url {{ github_server }}/{{ github_owner | default(github_account) }}/{{ github_repo }} \
6768
--token {{ registration.json.token }} --unattended --replace"
6869
args:
6970
chdir: "{{ runner_dir }}"

0 commit comments

Comments
 (0)