riemers / ansible-gitlab-runner

Ansible role to install gitlab-runner

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"No package matching 'gitlab-runner' is available"

Listecky opened this issue · comments

Hello, I am trying to use this role but I am facing an issue i'cant pass (it is worth to mention that I am new to ansible so it may be a rookie mistake).

Issue 1.

When I am running ansible-playbook I can observe that installation process is ongoing but at the end it returns message that it is missing gitlab-package.
I have a docker container from which I am running ansible.

The error I am getting:

  "msg": "No package matching 'gitlab-runner' is available"

Command I am using to run ansible-playbook:

 ansible-playbook -vvvv -I hosts.yml site.yml --check --extra-vars "ansible_user=USER ansible_password=PASSWORD ansible_become_password=PASSWORD"

main.yml with vars for riemers rule

gitlab_runner_coordinator_url: "gitlab-instance"
gitlab_runner_registration_token: "gitlab-token"
gitlab_runner_runners:
  - name: 'Example Docker GitLab Runner'
    executor: docker
    docker_image: 'test'
    tags:
      - node

site.yml:

- hosts: all
  become: true
  vars_files:
    - main.yml
  roles:
    - { role: riemers.gitlab-runner }

Dockerfile for a container hosting ansible:

FROM python:3.11

RUN python3 -m pip install ansible

RUN apt-get update
RUN apt-get install -y gnupg2
RUN apt-get install openssh-client
RUN apt-get install sshpass

RUN ansible-galaxy collection install community.general
RUN ansible-galaxy role install riemers.gitlab-runner

ENV ANSIBLE_HOST_KEY_CHECKING=False

Issue 2.

I also don't know what does it exactly mean, how should I provide a repository here?

gitlab_runner_skip_package_repo_install- Skip the APT or YUM repository installation (by default, false). You should provide a repository containing the needed packages before running this role.

Can you run the playook (maybe without -vvvv to reduce noise) and post the output (to see all the steps).

Thanks for your response, here is the whole log file from a job without "-vvvv".

Running with gitlab-runner 16.1.0 (865283c5)
  on host,

Resolving secrets
00:00

Preparing the "docker" executor
00:03
Using Docker executor with image  ...
Authenticating with credentials from job payload (GitLab Registry)
Pulling docker image .....
Using docker image .....

Preparing environment
Running on runner.......

Getting source from Git repository
00:02
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in .....
Checking out 2355fadd as detached HEAD ...
Skipping Git submodules setup

Executing "step_script" stage of the job script
00:28
Using docker image .. ...
$ python --version
Python 3.11.6
$ ansible-playbook -i host.yml site.yml --check --extra-vars "ansible_user=$USER ansible_password=$PASSWORD ansible_become_password=$PASSWORD"
PLAY [all] *********************************************************************
TASK [Gathering Facts] *********************************************************
ok: [host]
TASK [riemers.gitlab-runner : Load platform-specific variables] ****************
ok: [host]
TASK [riemers.gitlab-runner : Install Gitlab Runner (Container)] ***************
skipping: [host]
TASK [riemers.gitlab-runner : Install GitLab Runner (Unix)] ********************
[DEPRECATION WARNING]: Specifying a list of dictionaries for vars is deprecated
 in favor of specifying a dictionary. This feature will be removed in version 
2.18. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
included: /root/.ansible/roles/riemers.gitlab-runner/tasks/main-unix.yml for plkrasap1080
TASK [riemers.gitlab-runner : (Debian) Refresh package cache] ******************
changed: [host]
TASK [riemers.gitlab-runner : (Debian) Get Gitlab repository installation script] ***
changed: [host]
TASK [riemers.gitlab-runner : (Debian) Install Gitlab repository] **************
changed: [host]
TASK [riemers.gitlab-runner : (Debian) Update gitlab_runner_package_name] ******
skipping: [host]
TASK [riemers.gitlab-runner : (Debian) Set gitlab_runner_package_name] *********
ok: [host]
TASK [riemers.gitlab-runner : (Debian) Unhold GitLab Runner version] ***********
ok: [host]
TASK [riemers.gitlab-runner : (Debian) Install GitLab Runner] ******************
fatal: [host]: FAILED! => {"changed": false, "msg": "No package matching 'gitlab-runner' is available"}
PLAY RECAP *********************************************************************
host               : ok=8    changed=3    unreachable=0    failed=1    skipped=2    rescued=0    ignored=0   

Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1

If you can get inside the docker container, you can check if you can find the name of the gitlab runner or just do a search etc. Then you know at least some more where the error originates from.

BTW: Installing within the docker container is tricky because even though you fix this, the systemd task will fail (I doubt that you have systemd available inside your container)...

Maybe I didn't explained my use case well enough, sorry.

The way I would like to use this role:

I would like to install gitlab-runner instances and manage them from the pipeline on gitlab.
To do this, I use a docker container as a host for the Ansible, then I connect from this container to the computers (using ssh) on which I want to install gitlab-runner instances with Ansible.

Therefore I would say I don't need systemd inside this host container, gitlab-instances will be running on a ubuntu server.

The error above that I mentioned is not from a container, it is an error from the server shell I think.

Ohh, I see. Thx.

What is the output of those two commands for you:

xxx@runner-01:/etc/apt/sources.list.d$ cat runner_gitlab-runner.list
# this file was generated by packages.gitlab.com for
# the repository at https://packages.gitlab.com/runner/gitlab-runner
deb [signed-by=/usr/share/keyrings/runner_gitlab-runner-archive-keyring.gpg] https://packages.gitlab.com/runner/gitlab-runner/ubuntu/ jammy main
deb-src [signed-by=/usr/share/keyrings/runner_gitlab-runner-archive-keyring.gpg] https://packages.gitlab.com/runner/gitlab-runner/ubuntu/ jammy main


xxx@gl-01:/etc/apt/sources.list.d$ sudo apt install gitlab-runner
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
gitlab-runner is already the newest version (16.4.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

First command:

user@host:/etc/apt/sources.list.d$ cat runner_gitlab-runner.list
cat: runner_gitlab-runner.list: No such file or directory

Second command:

user@host:/etc/apt/sources.list.d$ sudo apt install gitlab-runner
[sudo] password for t-cicgwl: 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package gitlab-runner

it looks like it can't find it

after "sudo apt-get update" there is no difference, still the same error

PS. I've found similar issue on gitlab https://gitlab.com/gitlab-org/gitlab-runner/-/issues/3067

I've found the root cause, I was running ansible-playbook command with --check parameter, which is not downloading anything from urls, he just checks them. That's why gitlab-runner package was missing.

Maybe it would be a nice feature to allow to use this role with "--check".

But without the --check parameter I have different error:

TASK [riemers.gitlab-runner : (Debian) Refresh package cache] ******************
fatal: [host]: FAILED! => {"changed": false, "msg": "Failed to lock apt for exclusive operation: Failed to lock directory /var/lib/apt/lists/: E:Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)"}
(13: Permission denied)

My guess: You don't run it as root

It worked, I've had become_user in inventory file and it was causing this error, now the role installs gitlab-runner but did not respect vars from main.yml. The config.toml after a succesful run is almost empty, it contains only
)
item=concurrent = 8
check_interval = 0
shutdown_timeout = 0
[session_server]
session_timeout = 1800
)

no runners registered. Therefore I guess it does not respect vars including gitlab-registration token, gitlab-runner version and gitlab url.

That's how I added the vars file, I just copied the relative path to main.yml.

- hosts: all
  become: true
  vars_files:
    - roles/common/riemers.gitlab-runner/vars/main.yml
  roles:
    - { role: riemers.gitlab-runner }

any ideas?

Did you find the problem?

Yes, i solved the problem just by creating a directory "group_vars" and inside, i've created "all" variables file containing variables, then added it to vars_files and it worked. First instance of gitlab-runner is up and running. So my goal is reached.
I also found out that i cant update runner tags when running update "by_config_toml" with gitlab-runner 16.4, but "by_register" works fine, so i will stick to the second one.