Skip to content

Commit 2ab4e62

Browse files
Merge pull request #2 from MonolithProjects/develop
First fully working release
2 parents 13997d4 + 7a33191 commit 2ab4e62

File tree

17 files changed

+397
-68
lines changed

17 files changed

+397
-68
lines changed

.github/workflows/main.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: molecule test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- develop
8+
schedule:
9+
- cron: '0 6 * * 0'
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: checkout
16+
uses: actions/checkout@v2
17+
- name: molecule
18+
uses: robertdebock/molecule-action@2.0.0
19+
with:
20+
entrypoint: /usr/local/bin/molecule
21+
args: lint
22+
test:
23+
needs:
24+
- lint
25+
runs-on: ubuntu-latest
26+
strategy:
27+
fail-fast: false
28+
steps:
29+
- name: checkout
30+
uses: actions/checkout@v2
31+
with:
32+
path: "${{ github.repository }}"
33+
- name: molecule
34+
uses: robertdebock/molecule-action@2.0.0
35+
env:
36+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
molecule/default
1+
actions-runner-linux-*

README.md

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
11
GitHub Actions Runner
22
=========
33

4-
<a href="https://galaxy.ansible.com/monolithprojects/system_update"><img src="https://img.shields.io/ansible/quality/47118?style=flat&logo=ansible"/></a>
5-
<a href="https://galaxy.ansible.com/monolithprojects/system_update"><img src="https://img.shields.io/ansible/role/d/47118"/></a>
4+
<a href="https://galaxy.ansible.com/monolithprojects/ansible-github_actions_runner"><img src="https://img.shields.io/ansible/quality/47118?style=flat&logo=ansible"/></a>
5+
<a href="https://galaxy.ansible.com/monolithprojects/ansible-github_actions_runner"><img src="https://img.shields.io/ansible/role/d/47118"/></a>
6+
<a href="https://galaxy.ansible.com/monolithprojects/github_actions_runner"><img src="https://img.shields.io/github/v/release/MonolithProjects/github_actions_runner"/></a>
7+
<a href="https://github.com/MonolithProjects/ansible-github_actions_runner/actions"><img src="https://github.com/MonolithProjects/ansible-github_actions_runner/workflows/molecule%20test/badge.svg?branch=master"/></a>
68
<a href="https://github.com/MonolithProjects/ansible-github_actions_runner/blob/master/LICENSE"><img src="https://img.shields.io/github/license/MonolithProjects/ansible-github_actions_runner"/></a>
79

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

10-
**Note:**
11-
The role is in early development stage.
12-
Role is able to:
13-
- install and cofigure local runner
14-
- request reistration token
15-
- register the runner to GitHub
16-
17-
Currently is missing:
18-
- idempotency
19-
- runner unregistration
20-
- automated testing
2112

2213
Requirements
2314
------------
2415

25-
System must have access to the packages repository (Internet, Red Hat Satellite, etc.).
16+
System must have access to the GitHub.
2617

2718
CentOS/Fedora systems require EPEL repository.
2819

29-
`PERSONAL_ACCESS_TOKEN` variable needs to be exported to your environment.
20+
`PERSONAL_ACCESS_TOKEN` variable needs to be exported to your environment. The token has to have admin rights for the repo.
21+
Personal Access Token for your GitHub account can be created [here](https://github.com/settings/tokens).
3022

3123
Role Variables
3224
--------------
@@ -35,11 +27,17 @@ This is a copy from `defaults/main.yml`
3527

3628
```yaml
3729
# Directory where the local runner will be installed
38-
runner_dir: "/opt/actions-runner"
30+
runner_dir: /opt/actions-runner
3931

4032
# Version of the GitHub Actions Runner
4133
runner_version: "2.165.2"
4234

35+
# If found, replace already registered runner
36+
replace_runner: yes
37+
38+
# Do not show Ansible logs which may contain sensitive data (registration token)
39+
hide_sensitive_logs: yes
40+
4341
# Personal Access Token for your GitHub account
4442
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
4543

@@ -53,24 +51,47 @@ github_server: "https://github.com"
5351
# github_repo: "yourrepo"
5452
```
5553

54+
5655
Example Playbook
5756
----------------
5857

59-
Simple example.
58+
In this example the role will deploy (or redeploy) the GitHub Actions runner service (default version ins ) and register the runner for the GitHub repo.
59+
60+
```yaml
61+
---
62+
- name: GitHub Actions Runner
63+
hosts: all
64+
become: yes
65+
vars:
66+
- runner_version: "2.165.2"
67+
- runner_user: runner
68+
- github_account: myuser
69+
- github_repo: my_awesome_repo
70+
roles:
71+
- role: monolithprojects.github_actions_runner
72+
```
6073
74+
Here the GitHub Actions runners will be uninstalled, service stopped and unregistered from the GitHub.
6175
```yaml
6276
---
63-
- name: Converge
77+
- name: GitHub Actions Runner
6478
hosts: all
6579
become: yes
80+
tags:
81+
- uninstall
6682
vars:
83+
- runner_version: "2.165.2"
6784
- runner_user: runner
68-
- github_account: example
69-
- github_repo: example
85+
- github_account: myuser
86+
- github_repo: my_awesome_repo
7087
roles:
71-
- role: monolithprojects/github_actions_runner
88+
- role: monolithprojects.github_actions_runner
7289
```
7390
91+
ToDo
92+
----
93+
Full Debian/Ubuntu support
94+
7495
License
7596
-------
7697

defaults/main.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
---
22
# Directory where the local runner will be installed
3-
runner_dir: "/opt/actions-runner"
3+
runner_dir: /opt/actions-runner
44

55
# Version of the GitHub Actions Runner
66
runner_version: "2.165.2"
77

8+
# If found, replace already registered runner
9+
replace_runner: yes
10+
11+
# Do not show Ansible logs which may contain sensitive data (registration token)
12+
hide_sensitive_logs: yes
13+
814
# Personal Access Token for your GitHub account
915
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
1016

meta/main.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
- name: Fedora
1515
versions:
1616
- all
17-
- name: Debian
18-
versions:
19-
- jessie
20-
- stretch
21-
- name: Ubuntu
22-
versions:
23-
- xenial
24-
- bionic
17+
# - name: Debian
18+
# versions:
19+
# - jessie
20+
# - stretch
21+
# - name: Ubuntu
22+
# versions:
23+
# - xenial
24+
# - bionic
2525
galaxy_tags:
2626
- github
2727
- actions
@@ -30,4 +30,4 @@
3030
- runner
3131
- cicd
3232
dependencies:
33-
- role: robertdebock.epel
33+
- robertdebock.epel

molecule/default/Dockerfile.j2

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Molecule managed
2+
3+
{% if item.registry is defined %}
4+
FROM {{ item.registry.url }}/{{ item.image }}
5+
{% else %}
6+
FROM {{ item.image }}
7+
{% endif %}
8+
9+
{% if item.env is defined %}
10+
{% for var, value in item.env.items() %}
11+
{% if value %}
12+
ENV {{ var }} {{ value }}
13+
{% endif %}
14+
{% endfor %}
15+
{% endif %}
16+
17+
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates iproute2 && apt-get clean; \
18+
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash iproute && dnf clean all; \
19+
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash iproute && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
20+
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml iproute2 && zypper clean -a; \
21+
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
22+
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates iproute2 && xbps-remove -O; fi
23+
24+
ENV ANSIBLE_USER=ansible SUDO_GROUP=wheel DEPLOY_GROUP=deployer
25+
RUN set -xe \
26+
&& groupadd -r ${ANSIBLE_USER} \
27+
&& groupadd -r ${DEPLOY_GROUP} \
28+
&& useradd -m -g ${ANSIBLE_USER} ${ANSIBLE_USER} \
29+
&& usermod -aG ${SUDO_GROUP} ${ANSIBLE_USER} \
30+
&& usermod -aG ${DEPLOY_GROUP} ${ANSIBLE_USER} \
31+
&& sed -i "/^%${SUDO_GROUP}/s/ALL\$/NOPASSWD:ALL/g" /etc/sudoers

molecule/default/INSTALL.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
*******
2+
Docker driver installation guide
3+
*******
4+
5+
Requirements
6+
============
7+
8+
* Docker Engine
9+
10+
Install
11+
=======
12+
13+
Please refer to the `Virtual environment`_ documentation for installation best
14+
practices. If not using a virtual environment, please consider passing the
15+
widely recommended `'--user' flag`_ when invoking ``pip``.
16+
17+
.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
18+
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site
19+
20+
.. code-block:: bash
21+
22+
$ pip install 'molecule[docker]'
71.9 MB
Binary file not shown.

molecule/default/converge.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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
10+
roles:
11+
- role: ansible-github_actions_runner
12+
13+
- name: Uninstall
14+
user: ansible
15+
hosts: all
16+
become: yes
17+
tags:
18+
- uninstall
19+
vars:
20+
- runner_user: ansible
21+
- github_repo: ansible-github_actions_runner-testrepo
22+
- github_account: monolithprojects
23+
roles:
24+
- role: ansible-github_actions_runner

molecule/default/molecule.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
driver:
3+
name: docker
4+
lint: |
5+
yamllint .
6+
platforms:
7+
- name: CentOS7
8+
image: monolithprojects/systemd-centos7:latest
9+
command: /sbin/init
10+
tmpfs:
11+
- /run
12+
- /tmp
13+
volumes:
14+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
15+
privileged: no
16+
pre_build_image: yes
17+
- name: CentOS8
18+
image: monolithprojects/systemd-centos8:latest
19+
command: /sbin/init
20+
tmpfs:
21+
- /run
22+
- /tmp
23+
volumes:
24+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
25+
privileged: no
26+
pre_build_image: yes
27+
# - name: Ubuntu16
28+
# image: monolithprojects/systemd-ubuntu16:latest
29+
# command: /sbin/init
30+
# tmpfs:
31+
# - /run
32+
# - /tmp
33+
# volumes:
34+
# - /sys/fs/cgroup:/sys/fs/cgroup:ro
35+
# privileged: no
36+
# pre_build_image: yes
37+
# - name: Ubuntu18
38+
# image: monolithprojects/systemd-ubuntu18:latest
39+
# command: /sbin/init
40+
# tmpfs:
41+
# - /run
42+
# - /tmp
43+
# volumes:
44+
# - /sys/fs/cgroup:/sys/fs/cgroup:ro
45+
# privileged: no
46+
# pre_build_image: yes
47+
provisioner:
48+
name: ansible
49+
log: false
50+
# env:
51+
# PERSONAL_ACCESS_TOKEN: $PERSONAL_ACCESS_TOKEN
52+
inventory:
53+
host_vars:
54+
CentOS8:
55+
ansible_python_interpreter: /usr/bin/python3
56+
verifier:
57+
name: ansible
58+
dependency:
59+
name: galaxy
60+
options:
61+
ignore-certs: True
62+
ignore-errors: True
63+
scenario:
64+
name: default
65+
test_sequence:
66+
- dependency
67+
- lint
68+
- cleanup
69+
- destroy
70+
- syntax
71+
- create
72+
- prepare
73+
- converge
74+
- cleanup
75+
- destroy

molecule/default/requirements.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
- role: robertdebock.epel
3+
version: master
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
3+
import testinfra.utils.ansible_runner
4+
5+
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
6+
os.environ['MOLECULE_INVENTORY_FILE']
7+
).get_hosts('all')
8+
9+
10+
def test_hosts_file(host):
11+
f = host.file('/etc/hosts')
12+
13+
assert f.exists
14+
assert f.user == 'root'
15+
assert f.group == 'root'

0 commit comments

Comments
 (0)