ansible-github_actions_runner icon indicating copy to clipboard operation
ansible-github_actions_runner copied to clipboard

bug: Missing svc.sh error when runner_name already in use

Open gregerspoulsen opened this issue 2 years ago • 2 comments

Summary

When the role is executed with a 'runner_name' already present in the organization , it fails due to a missing svc.sh file. That gives the impression something is wrong with the role. This will happen if you incidentally use the same runner name twice or try to install it on a different machine without deregistering the original. It would be helpful if the role warns that the 'runner_name' is already in use and aborts.

Issue Type

Bug Report

Ansible Version

ansible [core 2.13.3rc1]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/vagrant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/vagrant/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]
  jinja version = 3.0.3
  libyaml = True

Steps to Reproduce

  1. Run the playbook below
  2. Delete /opt/action_runner/ or move to a different machine
  3. Run the playbook again
- name: Install GitHub Actions Runner
  hosts: localhost
  become: yes

  roles:
    - role: monolithprojects.github_actions_runner
      vars:
        - github_account: xxx
        - runner_org: yes
        - runner_on_ghes: yes
        - runner_labels:
          - my_runner

Expected Results

I would expect a warning or error that the runner_name is already in use instead of an error due to the missing svc.sh file (which is expected to be missing given that register_runner is skipped)

Actual Results

TASK [monolithprojects.github_actions_runner : Register runner] ********************************************************
skipping: [localhost]

TASK [monolithprojects.github_actions_runner : Replace registered runner] **********************************************
skipping: [localhost]

TASK [monolithprojects.github_actions_runner : Install service] ********************************************************
fatal: [localhost]: FAILED! => {"changed": false, "cmd": "./svc.sh install vagrant", "msg": "[Errno 2] No such file or directory: b'./svc.sh'", "rc": 2, "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

gregerspoulsen avatar Aug 10 '22 07:08 gregerspoulsen

I removed and not runner_org from 'when:' and it reinstalled my org runner. install_runner.yml file, line 95.

- name: Replace registered runner
  environment:
    RUNNER_ALLOW_RUNASROOT: "1"
  ansible.builtin.command:
    "{{ runner_dir }}/config.sh \
    --url {{ github_full_url }} \
    --token {{ registration.json.token }} \
    --name '{{ runner_name }}' \
    --labels {{ runner_labels | join(',') }} \
    --unattended \
    {{ runner_extra_config_args }} \
    --replace"
  args:
    chdir: "{{ runner_dir }}"
  become_user: "{{ runner_user }}"
  no_log: "{{ hide_sensitive_logs | bool }}"
  when: runner_name in registered_runners.json.runners|map(attribute='name')|list and reinstall_runner

ramiro-sr avatar Aug 07 '23 19:08 ramiro-sr

Thank you! We ran into this today. We had to remove the existing entry in https://github.com/organizations//settings/actions/runners, and then after that the installation worked.

stianlagstad avatar Jun 03 '24 07:06 stianlagstad