Skip to content

Commit

Permalink
Merge pull request #41 from MonolithProjects/develop
Browse files Browse the repository at this point in the history
- Added better way to uninstall runner
- Added option to use custom name for the runner
  • Loading branch information
MonolithProjects committed Nov 27, 2020
2 parents 1ac7acb + 94616c5 commit f664f82
Show file tree
Hide file tree
Showing 20 changed files with 215 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
release:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
steps:
- name: galaxy
uses: robertdebock/galaxy-action@1.0.1
Expand Down
63 changes: 0 additions & 63 deletions .github/workflows/lifecycle.yml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: molecule lint

on:
push:
branches:
- develop
- feature/*
jobs:
lint:
runs-on: ubuntu-18.04
strategy:
fail-fast: true
steps:
- name: checkout
uses: actions/checkout@v2
with:
path: "${{ github.repository }}"
- name: Molecule for Ansible - lint
uses: MonolithProjects/action-molecule@v1.4.0
with:
molecule_command: lint
21 changes: 16 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@ on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
schedule:
- cron: '0 6 * * 0'
jobs:
test:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
strategy:
fail-fast: false
fail-fast: true
steps:
- name: checkout
uses: actions/checkout@v2
with:
path: "${{ github.repository }}"
- name: Molecule for Ansible
uses: MonolithProjects/action-molecule@v1.3.0
- name: Molecule for Ansible - GHR Repository
uses: MonolithProjects/action-molecule@v1.4.0
env:
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
with:
molecule_command: test
- name: Molecule for Ansible - GHR Organization
uses: MonolithProjects/action-molecule@v1.4.0
env:
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
with:
molecule_command: test
scenario: organization
58 changes: 38 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
[![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)
[![License](https://img.shields.io/github/license/MonolithProjects/ansible-github_actions_runner)](https://github.com/MonolithProjects/ansible-github_actions_runner/blob/master/LICENSE)

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

## Requirements

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

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

## Role Variables

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

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

# If found, delete already existed runner before install
uninstall_runner: no
# If found on the server, delete already existed runner service before install
reinstall_runner: no

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

# GitHub address
github_server: "https://github.com"

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

# Is it runner for organization or not
# Is it the runner for organization or not
runner_org: no

# Account used for Runner registration (GitHub Repository user with admin rights or Organization owner)
# Name to assign to this runner in GitHub (hostname as default)
runner_name: "{{ lookup('pipe', 'hostname') }}"

# GitHub Repository user or Organization owner used for Runner registration
# github_account: "youruser"

# GitHub repository owner name (if other than github_account)
# github_owner: "yourorg"

# Github repository name
# github_repo: "yourrepo"
```

## Example Playbook

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

```yaml
---
- name: GitHub Actions Runner
- name: Install GitHub Actions Runner
hosts: all
user: ansible
become: yes
Expand All @@ -88,11 +95,11 @@ Runner service will run under the same user as the Ansible is using for ssh conn
- role: monolithprojects.github_actions_runner
```
Same example, but runner will be added to an organization
Same example as above, but runner will be added to an organization.
```yaml
---
- name: GitHub Actions Runner
- name: Install GitHub Actions Runner
hosts: all
user: ansible
become: yes
Expand All @@ -103,26 +110,37 @@ Same example, but runner will be added to an organization
- role: monolithprojects.github_actions_runner
```
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`.
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`.
The runner service will be *stopped*.

```yaml
---
- name: GitHub Actions Runner
- name: Stop GitHub Actions Runner
hosts: all
become: yes
vars:
- runner_version: "2.165.2"
- runner_user: runner-user
- github_account: github-access-user
- github_repo: my_awesome_repo
- runner_state: "stopped"
roles:
- role: monolithprojects.github_actions_runner
```

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.
In this example the Ansible role will uninstall the runner service and unregister it from the GitHub Repository.

```bash
ansible-playbook playbook.yml --tags uninstall -e "uninstall_runner=yes"
```yaml
---
- name: Uninstall GitHub Actions Runner
hosts: all
become: yes
vars:
- github_account: github-access-user
- github_repo: my_awesome_repo
- runner_state: "absent"
roles:
- role: monolithprojects.github_actions_runner
```

## License
Expand Down
20 changes: 13 additions & 7 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,32 @@ runner_dir: /opt/actions-runner
# Version of the GitHub Actions Runner
runner_version: "latest"

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

# If found, delete already existed runner before install
uninstall_runner: no
# If found on the server, delete already existed runner service before install
reinstall_runner: no

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

# GitHub address
github_server: "https://github.com"

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

# Is it runner for organization or not
# Is it the runner for organization or not
runner_org: no

# Name to assign to this runner in GitHub (hostname as default)
runner_name: "{{ ansible_hostname }}"

# GitHub Repository user or Organization owner used for Runner registration
# github_account: "youruser"

# GitHub repository owner name (if other than github_account)
# github_owner: "yourorg"

# Github repository name
# github_repo: "yourrepo"
# github_repo: "yourrepo"
12 changes: 12 additions & 0 deletions molecule/default/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Cleanup
user: ansible
hosts: all
become: yes
vars:
- runner_user: ansible
- github_repo: ansible-github_actions_runner-testrepo
- github_account: monolithprojects
- runner_state: absent
roles:
- ansible-github_actions_runner
17 changes: 16 additions & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
---
- name: Converge
- name: Install
user: ansible
hosts: all
become: yes
vars:
- runner_user: ansible
- github_repo: ansible-github_actions_runner-testrepo
- github_account: monolithprojects
- runner_version: "latest"
roles:
- robertdebock.epel
- ansible-github_actions_runner

- name: Reinstall
user: ansible
hosts: all
become: yes
vars:
- runner_user: ansible
- github_repo: ansible-github_actions_runner-testrepo
- github_account: monolithprojects
- reinstall_runner: yes
- runner_version: "latest"
roles:
- robertdebock.epel
- ansible-github_actions_runner
Loading

0 comments on commit f664f82

Please sign in to comment.