Skip to content

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

Open
@sandermvanvliet

Description

@sandermvanvliet

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions