semaphoreui / semaphore

Modern UI and powerful API for Ansible, Terraform, OpenTofu, PowerShell and other DevOps tools.
https://semaphoreui.com
MIT License
10.77k stars 1.08k forks source link

Getting 401 error code from Runner #1766

Closed jlopez994 closed 8 months ago

jlopez994 commented 9 months ago

Hi,

I'm trying to setup a runner with docker compose but after it manages to connect to my semaphore instance it keeps logging this message: Checking new jobs error, server returns code 401

This is the full log in case you need it:

ansible-semaphore-runner  | Loading environment...
ansible-semaphore-runner  | Staring runner...
ansible-semaphore-runner  | [defaults]
ansible-semaphore-runner  | host_key_checking = False
ansible-semaphore-runner  | stdout_callback = yaml
ansible-semaphore-runner  | bin_ansible_callbacks = yes
ansible-semaphore-runner  | Loading config
ansible-semaphore-runner  | Validating config
ansible-semaphore-runner  | time="2024-02-18T12:01:06Z" level=info msg="Trying to register on server"
ansible-semaphore-runner  | time="2024-02-18T12:01:06Z" level=info msg="Runner registered on server"
ansible-semaphore-runner  | time="2024-02-18T12:01:07Z" level=error msg="Checking new jobs error, server returns code 401"
ansible-semaphore-runner  | time="2024-02-18T12:01:08Z" level=error msg="Checking new jobs error, server returns code 401"
(...)

Also, this is my compose config for the runner:

--
services:
  semaphore-runner:
    container_name: ansible-semaphore-runner
    image: semaphoreui/runner
    volumes:
      - ./config/config.json:/etc/semaphore/config.json
      - ./service.json:/tmp/service
    restart: unless-stopped
    networks:
      - test

networks:
  test:
    external: true

And this is the configuration file content:

{
  "runner": {
    "registration_token": "test",
    "config_file": "/tmp/semaphore-runner.json",
    "api_url": "http://ansible-semaphore:3000/api",
    "max_parallel_tasks": 3
  }
}

Bot instances are running on the same machine. I also added these two lines to the main configuration:

"use_remote_runner": true,
"runner_registration_token": "test"

Thanks in advance!

plaurent-dev commented 8 months ago

Hi there, i've got the same on my side. Both server and runner are installed as service on different machines, same network. Ubuntu 22.04 server and semaphore version v2.9.58 on both.

As per the doc, on server, i've changed config file with

"runner_registration_token": "mytoken",
"use_remote_runner": true,

on runner,

{
  "runner": {
    "registration_token": "mytoken",
    "config_file": "/home/pierre/semaphore/config.json",
    "api_url": "http://ip-semaphore-server:3000/api",
    "max_parallel_tasks": 10
  }
}

Aftersudo systemctl restart semaphore on both.

On server,

● semaphore.service - Semaphore Ansible
     Loaded: loaded (/etc/systemd/system/semaphore.service; disabled; vendor preset: enabled)
     Active: active (running) since Wed 2024-03-27 10:11:05 CET; 5min ago
       Docs: https://github.com/ansible-semaphore/semaphore
   Main PID: 3905202 (semaphore)
      Tasks: 14 (limit: 18659)
     Memory: 12.9M
        CPU: 140ms
     CGroup: /system.slice/semaphore.service
             └─3905202 /usr/bin/semaphore server --config=/home/pierre/semaphore/config.json

mars 27 10:11:05 newnavi systemd[1]: Started Semaphore Ansible.
mars 27 10:11:05 newnavi semaphore[3905202]: Loading config
mars 27 10:11:05 newnavi semaphore[3905202]: Validating config
mars 27 10:11:05 newnavi semaphore[3905202]: MySQL plaurent@ipdatabase:3306 semaphore
mars 27 10:11:05 newnavi semaphore[3905202]: Tmp Path (projects home) /tmp/semaphore
mars 27 10:11:05 newnavi semaphore[3905202]: Semaphore v2.9.58
mars 27 10:11:05 newnavi semaphore[3905202]: Interface
mars 27 10:11:05 newnavi semaphore[3905202]: Port :3000
mars 27 10:11:05 newnavi semaphore[3905202]: Server is running

On runner:

● semaphore.service - Semaphore Ansible
     Loaded: loaded (/etc/systemd/system/semaphore.service; disabled; vendor preset: enabled)
     Active: active (running) since Wed 2024-03-27 09:17:15 UTC; 2s ago
       Docs: https://github.com/ansible-semaphore/semaphore
   Main PID: 114616 (semaphore)
      Tasks: 5 (limit: 18659)
     Memory: 1.8M
        CPU: 12ms
     CGroup: /system.slice/semaphore.service
             └─114616 /usr/bin/semaphore runner --config=/home/pierre/semaphore/config.json

mars 27 09:17:15 runnerserver systemd[1]: Started Semaphore Ansible.
mars 27 09:17:15 runnerserver semaphore[114616]: Loading config
mars 27 09:17:15 runnerserver semaphore[114616]: Validating config
mars 27 09:17:15 runnerserver semaphore[114616]: time="2024-03-27T09:17:15Z" level=info msg="Trying to register on server"
mars 27 09:17:15 runnerserver semaphore[114616]: time="2024-03-27T09:17:15Z" level=info msg="Runner registered on server"
mars 27 09:17:16 runnerserver semaphore[114616]: time="2024-03-27T09:17:16Z" level=error msg="Checking new jobs error, server returns code 401"
mars 27 09:17:17 runnerserver semaphore[114616]: time="2024-03-27T09:17:17Z" level=error msg="Checking new jobs error, server returns code 401"

Same on syslog,

> Mar 27 09:20:11 runnerserver systemd[1]: Started Semaphore Ansible.
> Mar 27 09:20:11 runnerserver semaphore[114860]: Loading config
> Mar 27 09:20:11 runnerserver semaphore[114860]: Validating config
> Mar 27 09:20:11 runnerserver semaphore[114860]: time="2024-03-27T09:20:11Z" level=info msg="Trying to register on server"
> Mar 27 09:20:11 runnerserver semaphore[114860]: time="2024-03-27T09:20:11Z" level=info msg="Runner registered on server"
> Mar 27 09:20:12 runnerserver semaphore[114860]: time="2024-03-27T09:20:12Z" level=error msg="Checking new jobs error, server returns code 401"
> Mar 27 09:20:13 runnerserver semaphore[114860]: time="2024-03-27T09:20:13Z" level=error msg="Checking new jobs error, server returns code 401"
> Mar 27 09:20:14 runnerserver semaphore[114860]: time="2024-03-27T09:20:14Z" level=error msg="Checking new jobs error, server returns code 401"
> Mar 27 09:20:15 runnerserver semaphore[114860]: time="2024-03-27T09:20:15Z" level=error msg="Checking new jobs error, server returns code 401"
> Mar 27 09:20:16 runnerserver semaphore[114860]: time="2024-03-27T09:20:16Z" level=error msg="Checking new jobs error, server returns code 401"
> Mar 27 09:20:17 runnerserver semaphore[114860]: time="2024-03-27T09:20:17Z" level=error msg="Checking new jobs error, server returns code 401"
> Mar 27 09:20:18 runnerserver semaphore[114860]: time="2024-03-27T09:20:18Z" level=error msg="Checking new jobs error, server returns code 401"
> Mar 27 09:20:19 runnerserver semaphore[114860]: time="2024-03-27T09:20:19Z" level=error msg="Checking new jobs error, server returns code 401"
> Mar 27 09:20:20 runnerserver semaphore[114860]: time="2024-03-27T09:20:20Z" level=error msg="Checking new jobs error, server returns code 401"

Danke !

fiftin commented 8 months ago

Hi @jlopez994, @plaurent-dev,

I found the same issue in your examples. It's because of bad documentation.

Runner use config file which you provided via --config <conf_path> option to start.

But in first start it is creates another config file with path runner. config_file. It must have different path, not --config <conf_path>. In this file Runner stores information which it get form the server: runner_id and runner_token.