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

Check mode is broken by ansible version validation #840

Open
Al-thi opened this issue Dec 18, 2024 · 0 comments · May be fixed by #841
Open

Check mode is broken by ansible version validation #840

Al-thi opened this issue Dec 18, 2024 · 0 comments · May be fixed by #841

Comments

@Al-thi
Copy link

Al-thi commented Dec 18, 2024

Caution

Remember to redact any sensitive information such as authentication credentials or license keys.

Describe the bug

TASK [nginxinc.nginx : Verify that you are using a supported Jinja2 version on your Ansible host] **********************************************************************************************************************************
fatal: [test.rtone.fr -> 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"}

To reproduce

Steps to reproduce the bug:

Just run a playbook including nginxinc.nginx in check mode (ansible-playbook -C my-playbook.yml)

Expected behavior

Check mode finishes without crashing and show the expected diff to be deployed on the remote target.

Your environment

  • Version of the Ansible NGINX role (or specific commit): 0.25.0
ansible [core 2.18.1]
  config file = /home/[USER]/code/[REPO]/ansible.cfg
  configured module search path = ['/home/[USER]/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.12/site-packages/ansible
  ansible collection location = /home/[USER]/code/[REPO]/external/collections
  executable location = /usr/bin/ansible
  python version = 3.12.7 (main, Oct  1 2024, 11:15:50) [GCC 14.2.1 20240910] (/usr/bin/python)
  jinja version = 3.1.4
  libyaml = True

Additional context (optional)

I know my version is not supported, but it seems there is a bug here:

I would rewrite this as follow to perform the command tasks even in check mode:

 - 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
+  check_mode: false
 - name: Extract the list of Ansible collections installed on your Ansible host
   ansible.builtin.command: ansible-galaxy collection list
   register: collection_list
   changed_when: false
   delegate_to: localhost
   become: false
+  check_mode: false
Al-thi added a commit to Al-thi/ansible-role-nginx that referenced this issue Dec 19, 2024
fix nginxinc#840

Since a6712e3, ansible and jinja versions are
validated to ensure supported versions are used.
This validation is done by delegating `command` tasks to localhost, and parsing
the standard output of the executed commands, e.g. `ansible --version`.

The `ansible.builtin.command` module is not run when in check mode, causing the
variable which is supposed to get the result of the command to be empty,
resulting in an error message in the following tasks that parse these result
variables.

This commit ensures the `command` tasks are run even in check_mode. As they do
no modification on localhost, this is not dangerous.
@Al-thi Al-thi linked a pull request Dec 19, 2024 that will close this issue
5 tasks
Al-thi added a commit to Al-thi/ansible-role-nginx that referenced this issue Dec 19, 2024
fix nginxinc#840

Since a6712e3, ansible and jinja versions are
validated to ensure supported versions are used.
This validation is done by delegating `command` tasks to localhost, and parsing
the standard output of the executed commands, e.g. `ansible --version`.

The `ansible.builtin.command` module is not run when in check mode, causing the
variable which is supposed to get the result of the command to be empty,
resulting in an error message in the following tasks that parse these result
variables.

This commit ensures the `command` tasks are run even in check_mode. As they do
no modification on localhost, this is not dangerous.

Signed-off-by: Alexis Thietard <[email protected]>
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

Successfully merging a pull request may close this issue.

1 participant