Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

How to Install and Configure GitHub Self-Hosted Runners Using Ansible



๐Ÿš€ 1. Introduction

GitHub Actions self-hosted runners let you run CI/CD jobs on your own machines instead of GitHub-hosted ones.
Using Ansible, you can automate the installation, registration, and management of runners across multiple serversโ€”securely and repeatably.

This tutorial covers:

  • What GitHub Runners are
  • Why use Ansible to manage them
  • Installation prerequisites
  • Step-by-step setup (two methods)
  • Real Ansible playbooks (systemd and Docker)
  • Troubleshooting and best practices

๐Ÿง  2. What is a GitHub Runner?

A GitHub Actions Runner is an agent process that runs your CI/CD jobs from GitHub.
When a workflow is triggered, GitHub dispatches jobs to available runners.

You can host runners:

  • GitHub-Hosted: Managed by GitHub (default)
  • Self-Hosted: You install and manage them (ideal for custom hardware, private environments, or cost control)

โš™๏ธ 3. Why Use Ansible for Runners

Manually registering and configuring self-hosted runners is tedious and error-prone.
Ansible simplifies this by:

โœ… Automating installation & upgrades
โœ… Managing multiple runners or servers
โœ… Handling registration tokens & environment variables securely
โœ… Supporting repeatable, idempotent deployments
โœ… Integrating easily with CI/CD pipelines or infrastructure as code


๐Ÿงฉ 4. Architecture Options

You have two main ways to deploy runners:

TypeManaged BySuitable ForIsolationExample Role
Systemd (Host)OS serviceLong-lived runnersSharedMonolithProjects
Containerized (Docker)Docker containersEphemeral/Scalable runnersHighcompscidr

๐Ÿงฐ 5. Prerequisites

GitHub Personal Access Token

Create a token (PAT) with the repo and admin:org or workflow scopes depending on whether itโ€™s repo- or org-level.

GitHub โ†’ Settings โ†’ Developer Settings โ†’ Personal Access Tokens โ†’ โ€œFine-grained tokensโ€ or โ€œClassicโ€ โ†’ Enable scopes:

  • repo
  • admin:org
  • workflow

Export it on your control node:

export GH_PAT="ghp_xxxxxxxxxxxxxxxxxxxxx"
Code language: JavaScript (javascript)

Ansible Installed

pip install ansible

Target Hosts

  • RHEL / CentOS / Ubuntu with Python installed
  • SSH access from control node

๐Ÿงฑ 6. Option A: Systemd Runners (Recommended for VM/Server)

Weโ€™ll use MonolithProjects/ansible-github_actions_runner.

Step 1: Install the Role

ansible-galaxy role install git+https://github.com/MonolithProjects/ansible-github_actions_runner.git,1.21.1
Code language: JavaScript (javascript)

or use requirements.yml:

---
roles:
  - name: monolithprojects.github_actions_runner
    src: https://github.com/MonolithProjects/ansible-github_actions_runner
    version: "1.21.1"
Code language: JavaScript (javascript)

then run:

ansible-galaxy install -r requirements.yml
Code language: CSS (css)

Step 2: Create Your Inventory

inventory.ini

[github_runners]
runner1 ansible_host=192.168.56.10 ansible_user=ec2-user

Step 3: Write the Playbook

install_runner.yml

- name: Install GitHub Runner via Ansible (Systemd)
  hosts: github_runners
  become: true

  vars:
    github_account: "my-org-or-user"
    github_repo: "my-repo"          # optional if org-level
    runner_user: "runner"
    runner_labels:
      - linux
      - ansible
    runner_state: present
    github_token: "{{ lookup('env','GH_PAT') }}"  # use env variable

  roles:
    - monolithprojects.github_actions_runner
Code language: PHP (php)

Step 4: Run the Playbook

ansible-playbook -i inventory.ini install_runner.yml
Code language: CSS (css)

โœ… This installs, registers, and enables the runner as a systemd service.
Check the service:

sudo systemctl status actions.runner*
Code language: CSS (css)

Step 5: Verify on GitHub

Go to
Repo โ†’ Settings โ†’ Actions โ†’ Runners
โ†’ Youโ€™ll see the new runner with your label and status = online.


๐Ÿณ 7. Option B: Dockerized Runners (for High Density & Isolation)

Weโ€™ll use compscidr/ansible-github-runner.

Step 1: Install Role

ansible-galaxy role install compscidr.github_runner
Code language: CSS (css)

Make sure Docker is available on your hosts:

ansible -m apt -a "name=docker.io state=present" all
Code language: JavaScript (javascript)

Step 2: Create Inventory

inventory.ini

[docker_runner_hosts]
runner2 ansible_host=192.168.56.11 ansible_user=ubuntu

Step 3: Playbook

docker_runner.yml

- name: Install Dockerized GitHub Runner
  hosts: docker_runner_hosts
  become: true
  vars:
    github_owner: "my-org-or-user"
    github_repo: "my-repo"
    github_token: "{{ lookup('env','GH_PAT') }}"
    github_runner_count: 3                 # creates 3 runners (containers)
    github_runner_labels:
      - docker
      - self-hosted
    github_runner_image: "ghcr.io/myoung34/github-runner:latest"
    github_runner_workdir: "/tmp/runner"
  roles:
    - compscidr.github_runner
Code language: PHP (php)

Step 4: Run Playbook

ansible-playbook -i inventory.ini docker_runner.yml
Code language: CSS (css)

This will:

  • Pull the container image
  • Register each container runner with GitHub
  • Start them automatically via Docker

Step 5: Validate

List containers:

docker ps

Check runners online at
GitHub โ†’ Settings โ†’ Actions โ†’ Runners


๐Ÿงฐ 8. Option C: Minimal Role (rolehippie)

Use if you want lightweight manual control.

ansible-galaxy role install rolehippie.github_runner
Code language: CSS (css)

Playbook

- name: Minimal GitHub Runner Setup
  hosts: all
  become: true
  vars:
    runner_workdir: /opt/actions-runner
    runner_labels: ["linux","self-hosted"]
    runner_repo: "my-org-or-user/my-repo"
    runner_token: "{{ lookup('env','RUNNER_REG_TOKEN') }}"
  roles:
    - rolehippie.github_runner
Code language: JavaScript (javascript)

Note: You must manually fetch a runner registration token using the GitHub REST API or UI before running this playbook.


๐Ÿงช 9. Validating the Runner

Once playbooks finish:

  1. Log in to your GitHub repo/org
    โ†’ Settings โ†’ Actions โ†’ Runners
  2. Verify status shows โ€œOnlineโ€
  3. Run a test workflow using your label:
name: Test Runner
on: [push]
jobs:
  test:
    runs-on: [self-hosted, ansible]
    steps:
      - run: echo "Hello from self-hosted runner!"
Code language: PHP (php)

โšก 10. Updating or Removing a Runner

To remove:

runner_state: absent
Code language: HTTP (http)

Then re-run your playbook โ€” it unregisters and stops the service.


๐Ÿงญ 11. Troubleshooting

ProblemPossible Fix
Runner not appearing in GitHubCheck token validity and scopes
Runner shows offlineCheck network and systemd logs
Docker containers exit quicklyVerify PAT and environment variables
โ€œPermission deniedโ€Ensure become: true or correct user privileges
Multiple runners overwrite each otherUse unique names or containerized approach

๐Ÿ” 12. Best Practices

โœ… Use Personal Access Tokens (PAT), not registration tokens in playbooks
โœ… Store tokens in Ansible Vault (ansible-vault encrypt_string)
โœ… Use labels to route jobs cleanly
โœ… Pin runner versions for reproducibility
โœ… Use Dockerized runners for ephemeral workloads
โœ… Rotate tokens periodically


๐Ÿ 13. Summary

Deployment TypeBest ForExample Role
Systemd RunnerLong-lived VM runnersMonolithProjects
Dockerized RunnerScalable, short-lived runnerscompscidr
Minimal DIYCustom/light setupsrolehippie

๐Ÿ“˜ 14. References


โœ… In summary:
If youโ€™re new to self-hosted runnersโ€”start with MonolithProjects (simple and reliable).
If you need scale and isolationโ€”use compscidr (Dockerized).
For ultimate control and minimal overheadโ€”rolehippie is fine for tinkering.


Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Top 10 AI Audit Sampling Optimization Tools: Features, Pros, Cons & Comparison

Introduction AI Audit Sampling Optimization Tools are platforms that use artificial intelligence, statistical modeling, and data analytics to improve how audit samples are selected, tested, and validated….

Read More

Top 10 AI GRC Evidence Collection Tools: Features, Pros, Cons & Comparison

Introduction AI GRC Evidence Collection Tools are platforms that help organizations automatically gather, organize, and validate compliance evidence across systems, applications, and workflows using AI-driven automation. In…

Read More

Top 10 AI Third-Party Risk Analytics Tools: Features, Pros, Cons & Comparison

Introduction AI Third-Party Risk Analytics tools are platforms that help organizations assess, monitor, and manage risks originating from external vendors, suppliers, partners, and service providers. These systems…

Read More

Top 10 AI Insider Trading Risk Detection Tools: Features, Pros, Cons & Comparison

Introduction AI Insider Trading Risk Detection tools use machine learning, natural language processing (NLP), behavioral analytics, and network graph modeling to identify suspicious trading behavior that may…

Read More

Top 10 AI AML Case Triage Assistants: Features, Pros, Cons & Comparison

Introduction AI AML (Anti-Money Laundering) Case Triage Assistants are intelligent systems designed to help financial institutions automatically prioritize, classify, investigate, and escalate suspicious financial activities. These tools…

Read More

Top 10 AI KYC Identity Verification with ML Tools: Features, Pros, Cons & Comparison

Introduction AI KYC (Know Your Customer) Identity Verification with Machine Learning refers to intelligent systems that verify customer identities using AI-powered document analysis, facial recognition, liveness detection,…

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Jason Mitchell
Jason Mitchell
6 months ago

This article delivers a clear and practical explanation of how to use Ansible to set up GitHub self-hosted runners โ€” automating what would otherwise be a tedious, manual process. I like how it outlines each step and the configuration required, making it much easier for DevOps teams to replicate across multiple hosts. The guide makes a strong case for why using infrastructure-as-code tools like Ansible boosts consistency, repeatability, and reduces the risk of human error in CI/CD setups. For anyone managing build automation or custom deployment pipelines, this post is a valuable resource that can save time and improve reliability.

1
0
Would love your thoughts, please comment.x
()
x