From 7f68835677fec470eeff21ce5588346436e1f99d Mon Sep 17 00:00:00 2001 From: Lukas Greve Date: Fri, 24 Oct 2025 12:32:10 +0200 Subject: [PATCH] Initial commit. Add Inventory --- ansible.cfg | 21 ++++++++++++++++ inventory.ini | 6 +++++ readme.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ setup.yml | 60 +++++++++++++++++++++++++++++++++++++++++++++ update.yml | 17 +++++++++++++ 5 files changed, 172 insertions(+) create mode 100644 ansible.cfg create mode 100644 inventory.ini create mode 100644 readme.md create mode 100644 setup.yml create mode 100644 update.yml diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..a2fcdae --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,21 @@ +# This file aontains Ansible-wide settings that apply to all operations +[defaults] +# Specifies the inventory file to use for inventory management +inventory = ./inventory.ini +# Enable host key checking for SSH connections +host_key_checking = True +# Specifies the private key file to use for SSH authentication +private_key_file = ~/.ssh/terraform_key +# Sets the default user for SSH connections +remote_user = groot +# Enables privilege escalation using sudo +become = yes +# Specifies the privilege escalation method to use +become_method = sudo + +# -o ControlMaster=auto +# Enables SSH connection multiplexing. Creates a master SSH connection that can be reused for multiple subsequent connections to the same host +# -o ControlPersist=60s +# Sets the persistence time for the master connection to 60 seconds +[ssh_connection] +ssh_args = -o ControlMaster=auto -o ControlPersist=60s diff --git a/inventory.ini b/inventory.ini new file mode 100644 index 0000000..35f7d35 --- /dev/null +++ b/inventory.ini @@ -0,0 +1,6 @@ +# This file defines targets (hosts, groups, host-specific variables) +[all] +rocky10 ansible_host=10.17.3.36 ansible_user=groot ansible_become=true + +[gitrunner] +rocky10 \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..ed34905 --- /dev/null +++ b/readme.md @@ -0,0 +1,68 @@ +# Gitea Runner Automation with Ansible + +This repository contains an Ansible playbook and configuration files to automate the deployment and configuration of a Gitea Runner on a Rocky Linux 10 VM. + +To deploy a Rocky Linux virtual machine, please go to [this repository](https://git.phyllo.me/IaC/advanced-libvirt-terraform-examples). + +## Repository Structure + +``` +. +├── ansible.cfg # Ansible configuration settings +├── inventory.ini # Host inventory definition +├── setup.yml # Main playbook for Gitea Runner configuration +├── update.yml # Playbook to ensure system is up-to-date + +``` + +## Prerequisites + +1. Ansible installed on your control machine +2. Access to a Rocky Linux 10 VM with IP `10.17.3.36` +3. SSH key authentication configured with `~/.ssh/terraform_key` +4. Root privileges or sudo access on the target VM + +## How to Use + +1. **Install Ansible** (if not already installed): + ```bash + # For CentOS/RHEL/Fedora + sudo yum install ansible + + # For Ubuntu/Debian + sudo apt update && sudo apt install ansible + ``` + +2. **Ensure SSH key exists**: + ```bash + ls ~/.ssh/terraform_key + ``` + +3. **Run the playbook**: + ```bash + ansible-playbook site.yml + ``` + +## What This Does + +This automation will: +1. Connect to the specified Rocky Linux VM +2. Update the system packages +3. Install necessary dependencies (git) +4. Create a dedicated gitea-runner user +5. Set hostname to rocky10 +6. Download and install Gitea Runner v0.2.13 +7. Configure systemd service for automatic startup +8. Start the Gitea Runner service + +The result is a fully configured Gitea Runner that will automatically start on system boot, ready to execute Gitea Actions workflows. + +## Troubleshooting + +If you encounter issues: +- Verify SSH connectivity to the target VM +- Ensure Ansible can reach the specified IP address +- Check that `~/.ssh/terraform_key` has correct permissions +- Review output logs for specific error messages + +For additional help with Ansible configuration, consult the [official Ansible documentation](https://docs.ansible.com/ansible/latest/index.html). \ No newline at end of file diff --git a/setup.yml b/setup.yml new file mode 100644 index 0000000..cd61f1d --- /dev/null +++ b/setup.yml @@ -0,0 +1,60 @@ +--- +- name: Initial one-time setup + hosts: gitrunner + become: yes + vars: + runner_name: "gitea-runner" + gitea_runner_version: "0.2.13" + + tasks: + - name: Install required packages + yum: + name: + - git + state: present + + - name: Create gitea runner user + user: + name: "{{ runner_name }}" + system: yes + shell: /bin/bash + home: "/var/lib/{{ runner_name }}" + create_home: yes + + - name: Set hostname to rocky10 + hostname: + name: rocky10 + + - name: Install Gitea Runner + uri: + url: "https://gitea.com/gitea/act_runner/releases/download/v{{ gitea_runner_version }}/act_runner-{{ gitea_runner_version }}-linux-amd64" + dest: "/usr/local/bin/gitea-runner" + mode: '0755' + status_code: 200 + follow_redirects: all + + - name: Create Gitea Runner service file + copy: + content: | + [Unit] + Description=Gitea Runner + After=network.target + + [Service] + Type=simple + User={{ runner_name }} + ExecStart=/usr/local/bin/gitea-runner + Restart=always + RestartSec=10 + + [Install] + WantedBy=multi-user.target + dest: /etc/systemd/system/gitea-runner.service + mode: '0644' + + - name: Ensure gitea-runner service is enabled and started + systemd: + name: gitea-runner + enabled: yes + state: started + daemon_reload: yes diff --git a/update.yml b/update.yml new file mode 100644 index 0000000..7e974f7 --- /dev/null +++ b/update.yml @@ -0,0 +1,17 @@ +--- +- name: Update system packages + hosts: gitrunner + become: yes + + tasks: + - name: Update system packages + yum: + name: "*" + state: latest + update_cache: yes + + - name: Force reboot after updates (safe for Rocky Linux) + reboot: + msg: "System reboot after package updates" + post_reboot_delay: 10 + timeout: 300