Skip to content

Role fails in Ansible Check mode #548

@gwvandesteeg

Description

@gwvandesteeg

Bug Overview

Role fails when run in check mode on ansible 2.16+

Expected Behavior

When I run the playbook in check mode all the roles should function correctly and check things without creating resources

Steps to Reproduce the Bug

  1. I have deployed/run the NGINX config Ansible role using the following playbook.yml...
    - role: nginxinc.nginx
      become: true
      vars:
        nginx_type: "opensource"
        nginx_manage_repo: false
        nginx_branch: stable
        nginx_setup_license: false
        nginx_modules:
          - geoip
        nginx_logrorate_conf_enable: true

    # configure nginx using the official nginx role
    - role: nginxinc.nginx_config
      become: true
      vars:
        nginx_config_start: true
        nginx_config_debug_output: true
        # don't try to upload TLS certificates, that's handled by cert-manager
        nginx_config_upload_ssl_enable: false
        nginx_config_cleanup: false
        nginx_config_cleanup_paths:
          - directory:
              - /etc/nginx/conf.d
            recurse: false
        nginx_config_cleanup_files:
          - /etc/nginx/conf.d/default.conf
        # replace the default config file with one from the template
        nginx_config_main_template_enable: true
        # could be www-data
        nginx_config_user: www-data
        # the rest of the config is irrelevant since the error is not related to the configuration of nginx
  1. I have seen the following error(s) on my terminal/logs...
TASK [nginxinc.nginx : Verify that you are using a supported Jinja2 version on your Ansible host] ****************************************************************************************
task path: /home/redacted/.ansible/roles/nginxinc.nginx/tasks/validate/validate.yml:19
Thursday 03 April 2025  14:27:28 +1300 (0:00:00.188)       0:51:45.577 ********
Thursday 03 April 2025  14:27:28 +1300 (0:00:00.188)       0:51:45.575 ********
fatal: [redacted -> 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"
}

Environment Details

  • Target deployment platforms: [e.g. AWS/GCP/local cluster/etc...] AWS EC2 accessed via a bastion host
  • Target OSs: [e.g. RHEL 9/Ubuntu 24.04/etc...] Ubuntu 22.04.5 LTS (GNU/Linux 6.8.0-1024-aws x86_64)
  • Host OS (where you are running Ansible from): [e.g. RHEL 9/Ubuntu 24.04/etc...] Ubuntu 24.04.2 LTS
  • Version of the NGINX Ansible role (or specific commit): [e.g. 0.25.0/commit hash]
    • src: nginxinc.nginx
      version: 0.25.0
    • src: nginxinc.nginx_config
      version: 0.7.1
  • Version of Ansible: [e.g. 2.16.5]
$ ansible --version
ansible [core 2.16.14]
  config file = /home/redacted/src/redacted/ansible.cfg
  configured module search path = ['/home/redacted/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/redacted/src/redacted/.venv/lib/python3.12/site-packages/ansible
  ansible collection location = /home/redacted/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/redacted/src/redacted/.venv/bin/ansible
  python version = 3.12.3 (main, Feb  4 2025, 14:48:35) [GCC 13.3.0] (/home/redacted/src/redacted/.venv/bin/python3)
  jinja version = 3.1.6
  libyaml = True
  • How is Ansible being managed: [e.g. CLI/pipeline/Automation Hub/etc...] CLI + Git + Makefile
  • Version of Jinja2 (if you are using any templating capability): [e.g. 3.1.1] - 3.1.6

Additional Context

Connection is from Localhost -> SSH Bastion host -> Target instance

$ cat ansible.cfg
[defaults]
hash_behaviour=merge
nocows=True
max_diff_size=1048576
host_key_checking=False
callbacks_enabled = timer, profile_tasks, profile_roles
forks=30
pipelining=True
timeout=30

[ssh_connection]
ssh_args = -4 -o ControlMaster=auto -o ControlPersist=120s

and

ansible_ssh_common_args: '-o ProxyCommand="ssh -4 -q -A -W %h:%p redacted-user@redacted-bastion-host"'

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions