Skip to content

Commit b961f5f

Browse files
Merge pull request #37 from MonolithProjects/develop
Add support for organization runner
2 parents d324193 + 7669af1 commit b961f5f

File tree

13 files changed

+281
-18
lines changed

13 files changed

+281
-18
lines changed

.github/workflows/lifecycle.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
with:
1919
path: "${{ github.repository }}"
2020
- name: Molecule for Ansible - lint
21-
uses: MonolithProjects/action-molecule@v1.3.0
21+
uses: MonolithProjects/action-molecule@v1.4.0
2222
with:
2323
molecule_command: lint
2424

@@ -33,15 +33,31 @@ jobs:
3333
with:
3434
path: "${{ github.repository }}"
3535
- name: Molecule for Ansible - converge Default
36-
uses: MonolithProjects/action-molecule@v1.3.0
36+
uses: MonolithProjects/action-molecule@v1.4.0
3737
env:
3838
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
3939
with:
4040
molecule_command: converge
4141
- name: Molecule for Ansible - converge tag uninstall
42-
uses: MonolithProjects/action-molecule@v1.3.0
42+
uses: MonolithProjects/action-molecule@v1.4.0
4343
env:
4444
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
4545
with:
4646
molecule_command: converge
47+
converge_extra_args: '-e "uninstall_runner=yes" --tags uninstall'
48+
49+
- name: Molecule for Ansible - converge organizations
50+
uses: MonolithProjects/[email protected]
51+
env:
52+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
53+
with:
54+
molecule_command: converge
55+
scenario: organization
56+
- name: Molecule for Ansible - converge organizations tag uninstall
57+
uses: MonolithProjects/[email protected]
58+
env:
59+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
60+
with:
61+
molecule_command: converge
62+
scenario: organization
4763
converge_extra_args: '-e "uninstall_runner=yes" --tags uninstall'

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ github_server: "https://github.com"
6060
# Personal Access Token
6161
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
6262

63+
# Is it runner for organization or not
64+
runner_org: no
65+
6366
# Account used for Runner registration (GitHub Repository user with admin rights or Organization owner)
6467
# github_account: "youruser"
6568

@@ -85,6 +88,21 @@ Runner service will run under the same user as the Ansible is using for ssh conn
8588
- role: monolithprojects.github_actions_runner
8689
```
8790
91+
Same example, but runner will be added to an organization
92+
93+
```yaml
94+
---
95+
- name: GitHub Actions Runner
96+
hosts: all
97+
user: ansible
98+
become: yes
99+
vars:
100+
- github_account: my_awesome_org
101+
- runner_org: true
102+
roles:
103+
- role: monolithprojects.github_actions_runner
104+
```
105+
88106
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`.
89107

90108
```yaml

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ github_server: "https://github.com"
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
27+
runner_org: no
28+
2629
# GitHub Repository user or Organization owner used for Runner registration
2730
# github_account: "youruser"
2831

handlers/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
---
22
# handlers file for ansible-github_actions_runner
3+
- name: Restart runner service
4+
service:
5+
name: "{{ runner_service }}"
6+
state: restarted

molecule/default/molecule.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ platforms:
2525
volumes:
2626
- /sys/fs/cgroup:/sys/fs/cgroup:ro
2727
privileged: yes
28-
pre_build_image: yes
29-
- name: Fedora31
30-
image: monolithprojects/systemd-fedora31:latest
31-
command: /sbin/init
32-
tmpfs:
33-
- /run
34-
- /tmp
35-
volumes:
36-
- /sys/fs/cgroup:/sys/fs/cgroup:ro
37-
privileged: yes
3828
pre_build_image: yes
3929
- name: Fedora32
4030
image: monolithprojects/systemd-fedora32:latest
@@ -132,5 +122,6 @@ scenario:
132122
- create
133123
- prepare
134124
- converge
125+
- idempotence
135126
- cleanup
136127
- destroy

molecule/organization/converge.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
- name: Converge
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-testorg
10+
- runner_org: yes
11+
roles:
12+
- robertdebock.epel
13+
- ansible-github_actions_runner

molecule/organization/molecule.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
driver:
3+
name: docker
4+
lint: |
5+
set -e
6+
yamllint .
7+
ansible-lint
8+
platforms:
9+
- name: CentOS7
10+
image: monolithprojects/systemd-centos7:latest
11+
command: /sbin/init
12+
tmpfs:
13+
- /run
14+
- /tmp
15+
volumes:
16+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
17+
privileged: yes
18+
pre_build_image: yes
19+
- name: CentOS8
20+
image: monolithprojects/systemd-centos8:latest
21+
command: /sbin/init
22+
tmpfs:
23+
- /run
24+
- /tmp
25+
volumes:
26+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
27+
privileged: yes
28+
pre_build_image: yes
29+
- name: Fedora32
30+
image: monolithprojects/systemd-fedora32:latest
31+
command: /sbin/init
32+
tmpfs:
33+
- /run
34+
- /tmp
35+
volumes:
36+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
37+
privileged: yes
38+
pre_build_image: yes
39+
- name: Ubuntu16
40+
image: monolithprojects/systemd-ubuntu16:latest
41+
command: /sbin/init
42+
tmpfs:
43+
- /run
44+
- /tmp
45+
volumes:
46+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
47+
privileged: yes
48+
pre_build_image: yes
49+
- name: Ubuntu18
50+
image: monolithprojects/systemd-ubuntu18:latest
51+
command: /sbin/init
52+
tmpfs:
53+
- /run
54+
- /tmp
55+
volumes:
56+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
57+
privileged: yes
58+
pre_build_image: yes
59+
- name: Ubuntu20
60+
image: monolithprojects/systemd-ubuntu20:latest
61+
command: /sbin/init
62+
tmpfs:
63+
- /run
64+
- /tmp
65+
volumes:
66+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
67+
privileged: yes
68+
pre_build_image: yes
69+
- name: Debian9
70+
image: monolithprojects/systemd-debian9:latest
71+
command: /sbin/init
72+
tmpfs:
73+
- /run
74+
- /tmp
75+
volumes:
76+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
77+
privileged: yes
78+
pre_build_image: yes
79+
- name: Debian10
80+
image: monolithprojects/systemd-debian10:latest
81+
command: /sbin/init
82+
tmpfs:
83+
- /run
84+
- /tmp
85+
volumes:
86+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
87+
privileged: yes
88+
pre_build_image: yes
89+
provisioner:
90+
name: ansible
91+
playbooks:
92+
converge: converge.yml
93+
cleanup: cleanup.yml
94+
log: false
95+
inventory:
96+
host_vars:
97+
CentOS8:
98+
ansible_python_interpreter: /usr/bin/python3
99+
Debian9:
100+
ansible_python_interpreter: /usr/bin/python3
101+
Debian10:
102+
ansible_python_interpreter: /usr/bin/python3
103+
Ubuntu18:
104+
ansible_python_interpreter: /usr/bin/python3
105+
Ubuntu20:
106+
ansible_python_interpreter: /usr/bin/python3
107+
verifier:
108+
name: ansible
109+
dependency:
110+
name: galaxy
111+
options:
112+
ignore-certs: True
113+
ignore-errors: True
114+
scenario:
115+
name: organization
116+
test_sequence:
117+
- dependency
118+
- lint
119+
- cleanup
120+
- destroy
121+
- syntax
122+
- create
123+
- prepare
124+
- converge
125+
- idempotence
126+
- cleanup
127+
- destroy
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- role: robertdebock.epel
3+
version: master
4+
# - role: monolithprojects.user_management
5+
# version: master

molecule/organization/verify.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
# This is an example playbook to execute Ansible tests.
3+
4+
- name: Verify
5+
hosts: all
6+
gather_facts: false
7+
tasks:
8+
- name: Example assertion
9+
assert:
10+
that: true

tasks/collect_info_org.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
- name: Get registration token (RUN ONCE)
3+
uri:
4+
url: "https://api.github.com/orgs/{{ github_account }}/actions/runners/registration-token"
5+
headers:
6+
Authorization: "token {{ access_token }}"
7+
Accept: "application/vnd.github.v3+json"
8+
method: POST
9+
status_code: 201
10+
force_basic_auth: yes
11+
register: registration
12+
run_once: yes
13+
tags:
14+
- install
15+
- uninstall
16+
17+
- name: Check currently registered runners (RUN ONCE)
18+
uri:
19+
url: "https://api.github.com/orgs/{{ github_account }}/actions/runners"
20+
headers:
21+
Authorization: "token {{ access_token }}"
22+
Accept: "application/vnd.github.v3+json"
23+
method: GET
24+
status_code: 200
25+
force_basic_auth: yes
26+
register: registered_runners
27+
run_once: yes
28+
tags:
29+
- install
30+
- uninstall
31+
32+
- name: Check service facts
33+
service_facts:
34+
tags:
35+
- install
36+
- uninstall
37+
38+
- name: Build service name
39+
set_fact:
40+
runner_service: "actions.runner.{{ github_account[:45] }}.{{ ansible_hostname }}.service"
41+
tags:
42+
- install
43+
- uninstall

0 commit comments

Comments
 (0)