Skip to content

Latest commit

 

History

History
137 lines (92 loc) · 3.92 KB

README.md

File metadata and controls

137 lines (92 loc) · 3.92 KB

Setup a server for a GitHub Action runner with Vagrant

Vagrant is a tool to build a VirtualBox virtual machine (VM).

We will use a Vagrant to create a VM and an Ansible playbook to install a GitHub Action runner on it. When done a GitHub action workflow configured with runs-on: self-hosted will run on that runner in the VM.

Prerequisites

Start VM

Virtual machine can be started from this (/ubuntu-vagrant) directory with

vagrant up

This will have started a Ubuntu 18.04 virtual machine in VirtualBox.

Test ssh connection to VM

Login with vagrant ssh and get the hostname with

vagrant ssh -c hostname

This should output vagrant, which is the hostname of the VM.

(If you get Host key verification failed error then clear previous key with ssh-keygen -R "[127.0.0.1]:2222" and try again)

To use other ssh client get the ssh config with

vagrant ssh-config

This will output something like

Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/verhoes/git/NLESC-JCER/linux_actions_runner/ubuntu-vagrant/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL

So to login with ssh client and to get hostname use

ssh -i .vagrant/machines/default/virtualbox/private_key -p 2222 [email protected] hostname

It should output vagrant, which is the hostname of the VM.

Configure

To use Ansible you need an inventory file. An example inventory file called hosts.example should be copied to hosts and updated to reflect your situation.

cp hosts.example hosts

Ansible must be configured for which GitHub account/organization and repository it should setup a runner for. The repository must be configured in github_account and github_repo fields in the hosts file. As a repository, you can use a duplicate of https://github.com/ci-for-science/example-python-1 repository which has a workflow that runs on a self-hosted runner or any repository which has a GitHub Action workflow that has runs-on: self-hosted.

The Ansible playbook uses Personal Access Token for GitHub account to register the runner. The token needs to have full admin rights for the repo. At the moment the checkbox that needs to be checked is called repo Full control of private repositories. The token can be created here.

The token should be set as the PAT environment variable.

export PAT=xxxxxxxxxxxxxxx

Install GitHub Action runner

To install GitHub Action runner we use an Ansible playbook to provision the VM.

Test that Ansible can ping server with

ansible vagrants -m ping

Should output something like

vagrant | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

(If ping fails please check the connection configuration in hosts file matches output of vagrant ssh-config)

The playbook uses roles from Ansible galaxy, they must be downloaded with

ansible-galaxy install -r requirements.yml

To provision VM use

ansible-playbook playbook.yml

The log of the runner can be viewed with

vagrant ssh -- journalctl -u actions.runner.*

Destroy VM

First unregister runner with

ansible-playbook playbook.yml --tags uninstall

To get rid of VM use

vagrant destroy