This guide installs GitLab Runner from the official package repository and registers it with GitLab.
gitlab-runner package- name: Deploy GitLab Runner
hosts: gitlab_runner
become: true
vars:
gitlab_url: https://gitlab.com
gitlab_runner_token: ""
gitlab_runner_executor: shell
gitlab_runner_description: ansible-runner-01
tasks:
- name: Install repository script prerequisites
ansible.builtin.package:
name:
- curl
- ca-certificates
state: present
- name: Add GitLab Runner repository on Debian family
ansible.builtin.shell: |
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | bash
args:
executable: /bin/bash
when: ansible_os_family == "Debian"
- name: Add GitLab Runner repository on RHEL family
ansible.builtin.shell: |
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | bash
args:
executable: /bin/bash
when: ansible_os_family == "RedHat"
- name: Install GitLab Runner
ansible.builtin.package:
name: gitlab-runner
state: present
- name: Enable and start GitLab Runner
ansible.builtin.systemd:
name: gitlab-runner
enabled: true
state: started
- name: Register runner non-interactively when token is provided
ansible.builtin.command: >
gitlab-runner register --non-interactive
--url {{ gitlab_url }}
--token {{ gitlab_runner_token }}
--executor {{ gitlab_runner_executor }}
--description {{ gitlab_runner_description }}
when: gitlab_runner_token | length > 0
ansible-playbook -i inventory.ini gitlab-runner-install.yml