--- # ============================================================================= # Gitea Actions Runner Deployment # ============================================================================= # Deploys act_runner for Gitea Actions CI/CD. # # Prerequisites: # 1. Gitea instance running with Actions enabled # 2. Runner registration token from Gitea admin # # Get registration token: # 1. Go to Gitea → Site Administration → Actions → Runners # 2. Click "Create new runner" # 3. Copy the registration token # # Usage: # ansible-playbook -i poc-inventory.yml playbook.yml -e vault_gitea_runner_token= # ============================================================================= - name: Deploy Gitea Actions Runner hosts: gitea_runner_servers become: true vars_files: - group_vars/gitea_runner_servers.yml pre_tasks: - name: Validate runner token is provided ansible.builtin.assert: that: - gitea_runner_token is defined - gitea_runner_token | length > 0 fail_msg: | Runner token not provided! Get it from: {{ gitea_url }}/admin/actions/runners Run with: -e vault_gitea_runner_token= tasks: # ========================================================================= # Docker (required for container-based jobs) # ========================================================================= - name: Check if Docker is installed ansible.builtin.command: docker --version register: docker_check changed_when: false failed_when: false - name: Fail if Docker not installed ansible.builtin.fail: msg: "Docker is required. Run gitea or netbird playbook first to install Docker." when: docker_check.rc != 0 # ========================================================================= # Create Runner Directory # ========================================================================= - name: Create runner directory ansible.builtin.file: path: "{{ gitea_runner_dir }}" state: directory mode: "0755" # ========================================================================= # Download act_runner # ========================================================================= - name: Download act_runner binary ansible.builtin.get_url: url: "https://gitea.com/gitea/act_runner/releases/download/v{{ gitea_runner_version }}/act_runner-{{ gitea_runner_version }}-linux-amd64" dest: "{{ gitea_runner_dir }}/act_runner" mode: "0755" # ========================================================================= # Register Runner # ========================================================================= - name: Check if runner is already registered ansible.builtin.stat: path: "{{ gitea_runner_dir }}/.runner" register: runner_config - name: Register runner with Gitea ansible.builtin.command: cmd: > {{ gitea_runner_dir }}/act_runner register --instance {{ gitea_url }} --token {{ gitea_runner_token }} --name {{ gitea_runner_name }} --labels {{ gitea_runner_labels }} --no-interactive chdir: "{{ gitea_runner_dir }}" when: not runner_config.stat.exists register: register_result - name: Show registration result ansible.builtin.debug: var: register_result.stdout_lines when: register_result is changed # ========================================================================= # Create Systemd Service # ========================================================================= - name: Create systemd service for runner ansible.builtin.copy: dest: /etc/systemd/system/gitea-runner.service mode: "0644" content: | [Unit] Description=Gitea Actions Runner After=network.target docker.service Requires=docker.service [Service] Type=simple User=root WorkingDirectory={{ gitea_runner_dir }} ExecStart={{ gitea_runner_dir }}/act_runner daemon Restart=always RestartSec=10 [Install] WantedBy=multi-user.target - name: Reload systemd ansible.builtin.systemd: daemon_reload: true - name: Start and enable runner service ansible.builtin.systemd: name: gitea-runner state: started enabled: true # ========================================================================= # Verify # ========================================================================= - name: Wait for runner to be active ansible.builtin.pause: seconds: 5 - name: Check runner status ansible.builtin.systemd: name: gitea-runner register: runner_status - name: Display deployment status ansible.builtin.debug: msg: | ============================================ Gitea Actions Runner Deployed! ============================================ Service status: {{ runner_status.status.ActiveState }} The runner should now appear in: {{ gitea_url }}/admin/actions/runners Labels available: {{ gitea_runner_labels }} View logs: journalctl -u gitea-runner -f ============================================