riemers / ansible-gitlab-runner

Ansible role to install gitlab-runner
MIT License
349 stars 262 forks source link

No condition to not run docker option configuration #275

Closed yoursweetginger closed 1 year ago

yoursweetginger commented 1 year ago

There is no condition to not run docker option configuration. It provides to fail tasks when not set docker executor and docker options in vars.

- hosts: runner_macos
  roles:
    - role: riemers.gitlab-runner
      vars: 
        gitlab_runner_registration_token: XXX
        gitlab_runner_coordinator_url: https://XXX/
        gitlab_runner_runners:
          - name: macos-notebook
            tags: 
              - macos
            executor: shell
            shell: bash
TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set runner docker image option] ****************************************************************************************************************************************
ok: [runner_macos]

TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set docker helper image option] ****************************************************************************************************************************************
ok: [runner_macos]

TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set docker privileged option] ******************************************************************************************************************************************
ok: [runner_macos]

TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set docker wait_for_services_timeout option] ***************************************************************************************************************************
ok: [runner_macos]

TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set docker tlsverify option] *******************************************************************************************************************************************
ok: [runner_macos]

TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set docker shm_size option] ********************************************************************************************************************************************
ok: [runner_macos]

TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set docker disable_cache option] ***************************************************************************************************************************************
ok: [runner_macos]

TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set docker DNS option] *************************************************************************************************************************************************
ok: [runner_macos]

TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set docker DNS search option] ******************************************************************************************************************************************
ok: [runner_macos]

TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set docker pull_policy option] *****************************************************************************************************************************************
ok: [runner_macos]

TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set docker volumes option] *********************************************************************************************************************************************
ok: [runner_macos]

TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set docker devices option] *********************************************************************************************************************************************
ok: [runner_macos]

TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set runner docker network option] **************************************************************************************************************************************
ok: [runner_macos]

TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set tls-cert-file option] **********************************************************************************************************************************************
ok: [runner_macos]

TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set tls-key-file option] ***********************************************************************************************************************************************
ok: [runner_macos]

TASK [riemers.gitlab-runner : conf[2/2]: runner[1/1]: Set additional services] ***********************************************************************************************************************************************
fatal: [runner_macos]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: the inline if-expression on line 1 evaluated to false and no else section was defined.\n\nThe error appears to be in '/home/iluha/.ansible/roles/riemers.gitlab-runner/tasks/update-config-runner.yml': line 361, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n#### [[runners.docker.services]] section ####\n- name:  \"{{ runn_name_prefix }} Set additional services\"\n  ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n    with_items:\n      - {{ foo }}\n\nShould be written as:\n\n    with_items:\n      - \"{{ foo }}\"\n"}
ansible [core 2.12.6]
  python version = 3.8.10 (default, May 26 2023, 14:05:08) [GCC 9.4.0]
  jinja version = 2.10.1
  libyaml = True
  riemers.gitlab-runner, v2.0.2
guenhter commented 1 year ago

Hm, I'd say (as the error message suggests) the line

content: "{{ lookup('template', 'config.runners.docker.services.j2') if gitlab_runner.docker_services is defined }}"

of the file update-config-runner.yml in the block:

#### [[runners.docker.services]] section ####
- name:  "{{ runn_name_prefix }} Set additional services"
  blockinfile:
    dest: "{{ temp_runner_config.path }}"
    content: "{{ lookup('template', 'config.runners.docker.services.j2') if gitlab_runner.docker_services is defined }}"
    state: "{{ 'present' if gitlab_runner.docker_services is defined else 'absent' }}"
    marker: "# {mark} runners.docker.services"
    insertafter: EOF
  check_mode: no
  notify:
  - restart_gitlab_runner
  - restart_gitlab_runner_macos

makes the problem. But it is strange because for me I also use shell runners and this is not problematic...

Maybe just adding an else branch to that if will sort out the issue, don't you think?

yoursweetginger commented 1 year ago

@guenhter

The error was: the inline if-expression on line 1 evaluated to false and no else section was defined

Yes, he's required else section.

github-actions[bot] commented 1 year ago

Seems this message did not get a lot of love. This does not mean it was not seen but time wise might not have made it to proper attention. This is just the clean up action ;)