riemers / ansible-gitlab-runner

Ansible role to install gitlab-runner
MIT License
350 stars 263 forks source link

Runner is not being unregistered from Gitlab instance, when setting `state: absent` #324

Closed michaelmell closed 4 months ago

michaelmell commented 6 months ago

Intro

I am having an issue with Gitlab runner not being unregistered correctly from the Gitlab instance when setting state from present to absent.

Please see the details under Error description.

Info about the environment

Ansible version

$ ansible --version
ansible [core 2.15.8]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/micha/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/micha/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.11.6 (main, Oct  8 2023, 05:06:43) [GCC 13.2.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Gitlab-runner role version

---
roles:
  # install role to deploy Gitlab runners:
  # https://galaxy.ansible.com/ui/standalone/roles/riemers/gitlab-runner
  - name: riemers.gitlab-runner
    version: "v2.0.3"

Playbook

- name: Install Gitlab runners
  become: true
  hosts: cicd01
  vars_files:
    - vars/gitlab_runners.yml
  roles:
    - riemers.gitlab-runner

Content of vars/gitlab_runners.yml is shown in the following section

Error description

This is the configuration:

gitlab_runner_container_install: true
gitlab_runner_container_image: gitlab/gitlab-runner
gitlab_runner_container_tag: v16.9.1
gitlab_runner_container_name: gitlab-runner
# config-directory that is mounted into the container and store the config.toml
gitlab_runner_container_mount_path: "/etc/gitlab-runner"

gitlab_runner_runners:
- name: "gitlab_runner_1"
    description: "Project: gitlab-runner-dind-tutorial"
    state: present
    url: "{{ gitlab_url }}"
    token: "{{ gitlab_prj_token__gitlab_runner_dind_tutorial }}"
    executor: docker
    docker_image: "docker:stable"

It creates and configures the Gitlab runner in /etc/gitlab/config.toml and registers it with our self-hosted Gitlab instance (as expected).

When I now change state configuration to absent, i.e.:

state: absent

it removes the runner configuration from /etc/gitlab/config.toml.

But it does not unregister/remove the runner from the Gitlab instance. (It is still shown under Settings -> CI/CD -> Project runners)

Furthermore, setting state back to present will register the runner again, so that it now exists twice in the Project runner section of the Gitlab instance.

Is this expected behavior?

riemers commented 5 months ago

I would say no, but check the code if it does a call to 'unregister' if the state is absent. If this is not there you could use the same call to register to unregister and add a task for that.

github-actions[bot] commented 4 months ago

Seems this message did not get a lot of love. This does not mean it was not seen but time wise might not have made it to proper attention. This is just the clean up action ;)