1 # Copyright (c) 2021 Red Hat, Inc.
4 # Cleber Rosa <crosa@redhat.com>
6 # This work is licensed under the terms of the GNU GPL, version 2 or
7 # later. See the COPYING file in the top-level directory.
9 # This is an ansible playbook file. Run it to set up systems with the
10 # gitlab-runner agent.
12 - name: Installation of gitlab-runner
18 msg: 'Checking for a valid GitLab registration token'
19 failed_when: "gitlab_runner_registration_token == 'PLEASE_PROVIDE_A_VALID_TOKEN'"
21 - name: Create a group for the gitlab-runner service
25 - name: Create a user for the gitlab-runner service
29 comment: GitLab Runner
30 home: /home/gitlab-runner
33 - name: Remove the .bash_logout file when on Ubuntu systems
35 path: /home/gitlab-runner/.bash_logout
37 when: "ansible_facts['distribution'] == 'Ubuntu'"
39 - name: Set the Operating System for gitlab-runner
41 gitlab_runner_os: "{{ ansible_facts[\"system\"]|lower }}"
43 msg: gitlab-runner OS is {{ gitlab_runner_os }}
45 - name: Set the architecture for gitlab-runner
47 gitlab_runner_arch: "{{ ansible_to_gitlab_arch[ansible_facts[\"architecture\"]] }}"
49 msg: gitlab-runner arch is {{ gitlab_runner_arch }}
51 - name: Download the matching gitlab-runner
54 url: "https://gitlab-runner-downloads.s3.amazonaws.com/latest/deb/gitlab-runner_{{ gitlab_runner_arch }}.deb"
56 - name: Install gitlab-runner via package manager
57 apt: deb="/root/gitlab-runner_{{ gitlab_runner_arch }}.deb"
59 - name: Register the gitlab-runner
60 command: "/usr/bin/gitlab-runner register --non-interactive --url {{ gitlab_runner_server_url }} --registration-token {{ gitlab_runner_registration_token }} --executor shell --tag-list {{ ansible_facts[\"architecture\"] }},{{ ansible_facts[\"distribution\"]|lower }}_{{ ansible_facts[\"distribution_version\"] }} --description '{{ ansible_facts[\"distribution\"] }} {{ ansible_facts[\"distribution_version\"] }} {{ ansible_facts[\"architecture\"] }} ({{ ansible_facts[\"os_family\"] }})'"
62 # The secondary runner will still run under the single gitlab-runner service
63 - name: Register secondary gitlab-runner
64 command: "/usr/bin/gitlab-runner register --non-interactive --url {{ gitlab_runner_server_url }} --registration-token {{ gitlab_runner_registration_token }} --executor shell --tag-list aarch32,{{ ansible_facts[\"distribution\"]|lower }}_{{ ansible_facts[\"distribution_version\"] }} --description '{{ ansible_facts[\"distribution\"] }} {{ ansible_facts[\"distribution_version\"] }} {{ ansible_facts[\"architecture\"] }} ({{ ansible_facts[\"os_family\"] }})'"
66 - ansible_facts['distribution'] == 'Ubuntu'
67 - ansible_facts['architecture'] == 'aarch64'
68 - ansible_facts['distribution_version'] == '22.04'
70 - name: Install the gitlab-runner service using its own functionality
71 command: "/usr/bin/gitlab-runner install --user gitlab-runner --working-directory /home/gitlab-runner"
72 register: gitlab_runner_install_service_result
73 failed_when: "gitlab_runner_install_service_result.rc != 0 and \"already exists\" not in gitlab_runner_install_service_result.stderr"
75 - name: Enable the gitlab-runner service