MonolithProjects / ansible-github_actions_runner

Ansible Role to deploy GitHub Actions self-hosted runner
https://galaxy.ansible.com/ui/standalone/roles/monolithprojects/github_actions_runner/
MIT License
178 stars 72 forks source link

Runner doesn't start on RedHat when installing the first time.] #201

Closed bschonec closed 4 months ago

bschonec commented 4 months ago

Summary

The startup of the runner fails because the dictionary "{{ ansible_facts.services }}" doesn't contain the key for the runner service.

Issue Type

Bug Report

Ansible Version

ansible [core 2.14.9]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/example/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/example/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.18 (main, Jan  4 2024, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Steps to Reproduce

Run the role on RHEL 9.3.

Expected Results

Expect that the runner starts.

Actual Results

The runner doesn't start because the [{{ ansible_facts.services }}](https://github.com/MonolithProjects/ansible-github_actions_runner/blob/1662b2980f21b02c5e480d0ac82cc2c7fd768085/tasks/install_runner.yml#L132) variable doesn't contain the name of the runner as a service.  The ansible variable {{ ansible_facts.services }} runs before the runner is installed and configured, therefore [the start and enable](https://github.com/MonolithProjects/ansible-github_actions_runner/blob/1662b2980f21b02c5e480d0ac82cc2c7fd768085/tasks/install_runner.yml#L122) task fails.

I recommend modifying the line thusly:

`  when: >
    ansible_facts.system != 'Darwin' and
    runner_state|lower == "started" and
    ansible_facts.services[(runner_service.content | b64decode) | trim ]['state'] != 'running'`
to

`  when: >
    ansible_facts.system != 'Darwin' and
    runner_state|lower == "started" and
    ansible_facts.services[(runner_service.content | b64decode) | trim ]['state'] | default('stopped') != 'running'`

This will ensure that the ansible_facts.services will return a default of 'stopped' instead of erroring out because the runner_service.content key is missing from the ansible_facts.services dictionary.
bschonec commented 4 months ago

202