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

ansible-playbook --check fails on jinja2 version check #10

Open
sandermvanvliet opened this issue Jan 15, 2025 · 0 comments
Open

ansible-playbook --check fails on jinja2 version check #10

sandermvanvliet opened this issue Jan 15, 2025 · 0 comments

Comments

@sandermvanvliet
Copy link

Note: This is not really a bug but something to be aware of.

Describe the bug

When you run ansible-playbook --check on a playbook that includes the nginxinc.nginx role it will fail on the Verify that you are using a supported Jinja2 version on your Ansible host task with this error:

fatal: [somehost -> localhost]: FAILED! => {"msg": "Unexpected templating type error occurred on (Jinja2 {{ jinja2_version['stdout'] | regex_search('jinja version = ([\\d.]+)', '\\1') | first }} is supported.): 'NoneType' object is not iterable. 'NoneType' object is not iterable"}

The root cause for this isn't a missing package but rather that ansible --version refuses to run in check mode.

To reproduce

Create a new playbook repro.yml like so:

- name: Repro
  hosts: somehost
  tasks:
  - name: Extract the version of Jinja2 installed on your Ansible host
    ansible.builtin.command: ansible --version
    register: jinja2_version
    changed_when: false
    delegate_to: localhost
    become: false

  - name: Debug
    ansible.builtin.debug:
        msg: "{{ jinja2_version }}"

Now run ansible-playbook --check repro.yml and observe the output:

TASK [Debug] ***************************************************************
ok: [somehost] => {
    "msg": {
        "changed": false,
        "cmd": [
            "ansible",
            "--version"
        ],
        "delta": null,
        "end": null,
        "failed": false,
        "msg": "Command would have run if not in check mode",
        "rc": 0,
        "skipped": true,
        "start": null,
        "stderr": "",
        "stderr_lines": [],
        "stdout": "",
        "stdout_lines": []
    }
}

here you'll see that stdout is empty and msg indicates that: Command would have run if not in check mode

Expected behavior

The check passes.

Potential resolution

If the Jinja2 version check could obtain the version without running ansible directly (and hitting the --check switch) that would resolve this problem.
However that may or may not be possible so it's most likely something that is not relevant to this role.

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

1 participant