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
189 stars 77 forks source link

bug: Role fails if `runner_version` var has different values for different hosts #206

Open bissquit opened 6 months ago

bissquit commented 6 months ago

Summary

Let's say we have host-1 with runner_version: 2.316.1 and host-2 with runner_version: "latest". Role will fail in that case. I suppose it's because the following task has when: runner_version == "latest" condition:

    - name: Find the latest runner version (RUN ONCE)
      ansible.builtin.uri:
        url: "https://api.github.com/repos/{{ runner_download_repository }}/releases/latest"
        headers:
          Content-Type: "application/json"
        method: GET
        return_content: true
        status_code: 200
        body_format: json
      check_mode: false
      register: api_response
      run_once: true
      become: false
      delegate_to: localhost
      when: runner_version == "latest"

Issue Type

Bug Report

Ansible Version

ansible [core 2.12.6]
  config file = /infra-github-runners/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
  jinja version = 3.1.2
  libyaml = True

Steps to Reproduce

  1. Configure environment like the following:
TASK [debug] *******************************************************************
ok: [host-1] => {
    "runner_version": "2.316.1"
}
ok: [host-2] => {
    "runner_version": "latest"
}
  1. Run role against two hosts
  2. Output will be the following (shortened):
    
    TASK [ansible-github_actions_runner : Find the latest runner version (RUN ONCE)] ***
    skipping: [host-1]

... TASK [ansible-github_actions_runner : Set runner_version variable (If latest)] *** skipping: [host-1] fatal: [host-2]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'json'\n\nThe error appears to be in '/__w/infra-github-runners/infra-github-runners/roles/ansible-github_actions_runner/tasks/install_runner.yml': line 10, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Set runner_version variable (If latest)\n ^ here\n"}


### Expected Results

`api_response` is set for all hosts in play

### Actual Results

```console
`api_response` is set only if the first host has `runner_version: "latest"`