Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set additional services is failing due to missing variable #294

Closed
kakawait opened this issue Nov 15, 2023 · 8 comments
Closed

Set additional services is failing due to missing variable #294

kakawait opened this issue Nov 15, 2023 · 8 comments

Comments

@kakawait
Copy link

Hello

I've issue when using role without services

Here my roles/requirements.yml

- name: riemers.ansible-gitlab-runner
  src: https://github.com/riemers/ansible-gitlab-runner/archive/v2.0.3.tar.gz

I've also tried without the src, but I've added src after to be sure that I'm correctly fetching 2.0.3

# ansible-galaxy install -r roles/requirements.yml --force
Starting galaxy role install process
- changing role riemers.ansible-gitlab-runner from v2.0.3 to unspecified
- downloading role from https://github.com/riemers/ansible-gitlab-runner/archive/v2.0.3.tar.gz
- extracting riemers.ansible-gitlab-runner to /root/.ansible/roles/riemers.ansible-gitlab-runner
- riemers.ansible-gitlab-runner was installed successfully

and I've

TASK [riemers.ansible-gitlab-runner : conf[2/2]: runner[1/1]: Set additional services] *****************************************************************************************************
fatal: [gitlab.blabla]: 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 '/root/.ansible/roles/riemers.ansible-gitlab-runner/tasks/update-config-runner.yml': line 402, 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"}

with following usage

- import_role:
     name: riemers.gitlab-runner

and variables

gitlab_runner_registration_token: THE_TOKEN
gitlab_runner_coordinator_url: https://gitlab.blaba/ci
gitlab_runner_windows_service_user: "domain\\user"
gitlab_runner_windows_service_password: password
# A list of runners to register and configure
gitlab_runner_runners:
    # The identifier of the runner.
  - name: "{{ inventory_hostname }} - shell"
    # set to 'absent' if you want to delete the runner. Defaults to 'present'.
    state: present
    # The executor used by the runner.
    executor: 'shell'
    shell: "{{ (ansible_system == 'Linux') | ternary('bash', 'powershell') }}"
    # Set maximum build log size in kilobytes.
    output_limit: 4096
    # Maximum number of jobs to run concurrently on this specific runner.
    # Defaults to 0, simply means don't limit.
    concurrent_specific: '5'
    # The tags assigned to the runner.
    tags:
      - "{{ inventory_hostname }}"
      - "shell"
      - "{{ (ansible_system == 'Linux') | ternary('linux', 'windows') }}"
    # Indicates whether this runner can pick jobs without tags.
    run_untagged: false
    # Docker privileged mode
    docker_privileged: false
    # Runner Locked. When a runner is locked, it cannot be assigned to other projects
    locked: 'false'
    # Custom environment variables injected to registration command
    env_vars: []

However it works if I'm downgrading to v1.6.50

May I missed something?

@guenhter
Copy link
Collaborator

This was introduced with #254

@guenhter
Copy link
Collaborator

What version of ansible do you use?

@kakawait
Copy link
Author

What version of ansible do you use?

I'm using

ansible [core 2.12.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.12 (default, Sep 16 2021, 10:46:05) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
  jinja version = 2.10.3
  libyaml = True

To be honest just used pre-packaged (dnf) version, but I could upgrade if required more recent version

@guenhter
Copy link
Collaborator

Can you run this two tasks to see if they pass on your system? (this is I think the issue on your end but I'm not 100% certain so that experiment would be helpful).

    - file:
        path: /tmp/foo1
        state: touch
    - blockinfile:
        dest: "/tmp/foo1"
        content: "{{ lookup('template', 'config.runners.docker.services.j2') if nondefinedvariable is defined }}"
        state: "{{ 'present' if nondefinedvariable is defined else 'absent' }}"
        marker: "# {mark} runners.docker.services"
        insertafter: EOF
      check_mode: no

@kakawait
Copy link
Author

Can you run this two tasks to see if they pass on your system? (this is I think the issue on your end but I'm not 100% certain so that experiment would be helpful).

    - file:
        path: /tmp/foo1
        state: touch
    - blockinfile:
        dest: "/tmp/foo1"
        content: "{{ lookup('template', 'config.runners.docker.services.j2') if nondefinedvariable is defined }}"
        state: "{{ 'present' if nondefinedvariable is defined else 'absent' }}"
        marker: "# {mark} runners.docker.services"
        insertafter: EOF
      check_mode: no

Same issue

# ansible-playbook --connection=local --inventory inventory.yml t.yml

PLAY [runner] *********************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ************************************************************************************************************************************************************************************************************************
ok: [gitlab.blabla]

TASK [file] ***********************************************************************************************************************************************************************************************************************************
changed: [gitlab.blabla]

TASK [blockinfile] ****************************************************************************************************************************************************************************************************************************
fatal: [gitlab.blabla]: 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 '/tmp/gitlab-ansible-playbook/t.yml': line 6, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n        state: touch\n    - blockinfile:\n      ^ here\n"}

PLAY RECAP ************************************************************************************************************************************************************************************************************************************
gitlab.blabla       : ok=2    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

# cat t.yml
- hosts: runner
  tasks:
    - file:
        path: /tmp/foo1
        state: touch
    - blockinfile:
        dest: "/tmp/foo1"
        content: "{{ lookup('template', 'config.runners.docker.services.j2') if nondefinedvariable is defined }}"
        state: "{{ 'present' if nondefinedvariable is defined else 'absent' }}"
        marker: "# {mark} runners.docker.services"
        insertafter: EOF
      check_mode: no

@guenhter
Copy link
Collaborator

Alright, then I'm pretty certain that you issue is the Ansible/jinja version.
I run this experiment with

ansible [core 2.12.2]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
  jinja version = 3.1.2
  libyaml = True

and there it works.

Maybe you can upgrade and see if it works.

@kakawait
Copy link
Author

Alright, then I'm pretty certain that you issue is the Ansible/jinja version. I run this experiment with

ansible [core 2.12.2]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
  jinja version = 3.1.2
  libyaml = True

and there it works.

Maybe you can upgrade and see if it works.

Yes I think high chance related to jinja version but I've to check how to upgrade because seems to be embedded with ansible because my pip3 show jinja2 does not return the same version.

I'll keep you in touch. But I think we can already close the issue if is related to old version of jinja

@guenhter
Copy link
Collaborator

I will close this for the moment because it seems to be a version issue. Feel free to reopen it in case I'm wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants