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

"AnsibleUndefinedVariable: the inline if-expression on line 9 in 'http/grpc.j2' evaluated to false and no else section was defined."} #94

Closed
ghomem opened this issue Mar 22, 2021 · 11 comments · Fixed by #95
Assignees
Labels
bug Something isn't working
Milestone

Comments

@ghomem
Copy link

ghomem commented Mar 22, 2021

Describe the bug

Can't apply configuration when the http section is enabled. I get the following error:

"AnsibleUndefinedVariable: the inline if-expression on line 9 in 'http/grpc.j2' evaluated to false and no else section was defined."}

The configuration has been copied from this example:

https://github.com/nginxinc/ansible-role-nginx-config/blob/main/molecule/default/converge.yml

To reproduce

Steps to reproduce the behavior:

# https://github.com/nginxinc/ansible-role-nginx
- name: Install NGINX
  include_role:
    name: nginxinc.nginx
  vars:
    nginx_install_from: os_repository
    nginx_start: false
    nginx_type: opensource
    nginx_state: present

# https://github.com/nginxinc/ansible-role-nginx-config
- name: Configure NGINX
  include_role:
    name: nginxinc.nginx_config
  vars:
    nginx_config_start: false
    nginx_config_cleanup: true
    nginx_config_debug_output: true
    nginx_config_debug_tasks: true

    # top level nginx configuration
    nginx_config_main_template_enable: true
    nginx_config_main_template:
      template_file: nginx.conf.j2
      conf_file_name: nginx.conf
      conf_file_location: /etc/nginx/
      worker_connections: 1024
      http_custom_includes:
        - "/etc/nginx/sites-enabled/*.conf"
      user: www-data
      worker_processes: auto
      pid: /var/run/nginx.pid

      # http configuration section
      http_enable: true
      http_settings:
        grpc_global:
          bind:
            address: $remote_addr
            transparent: false
          buffer_size: 4k
          connect_timeout: 60s
[...]

Expected behavior

I expected the configuration to apply without errors

Your environment:

  • nginxinc.nginx_config, 0.3.3
  • nginxinc.nginx, 0.19.1
  • ansible: 2.9.6+dfsg-1
  • ubuntu 20.04

Additional context

Add any other context about the problem here.

@alessfg alessfg self-assigned this Mar 22, 2021
@alessfg alessfg added the bug Something isn't working label Mar 22, 2021
@alessfg alessfg added this to the 0.4.0 milestone Mar 22, 2021
@alessfg
Copy link
Collaborator

alessfg commented Mar 22, 2021

Found the issue. PR coming shortly.

@ghomem
Copy link
Author

ghomem commented Mar 22, 2021

thank you for the quick response, I will follow up the development of this issue.

@alessfg
Copy link
Collaborator

alessfg commented Mar 22, 2021

Can you pull from main and check if the latest PR fixed your issue? You might need to do some further tweaks to your template since there's been a few breaking changes since 0.3.3, but hopefully the updated examples in the molecule tests should help you get there.

@ghomem
Copy link
Author

ghomem commented Mar 22, 2021

I can, but I am still testing other configuration situations. I just found a similar situation with gzip:

        gzip:
          enable: true
          buffers:
            number: 32
            size: 4k
          comp_level: 1
          disable:
            - '"msie6"'
          http_version: 1.1
          min_length: 20
          proxied:
            - expired
          types:
            - text/html
          vary: false
fatal: [testing-snap05.snapview.net]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: the inline if-expression on line 27 in 'http/gzip.j2' evaluated to false and no else section was defined."}

Seems to be related to the "proxied" line.

@alessfg
Copy link
Collaborator

alessfg commented Mar 22, 2021

That's a weirder error. Can you check which version of Jinja2 you are using? Tests for both the previous and this error pass just fine, and I've seen templates fail for other people when using older versions of Jinja2.

@ghomem
Copy link
Author

ghomem commented Mar 22, 2021

Here is the version:

python3-jinja2 2.10.1-2

I am also having trouble in applying a proxy: section under http_settings. It keeps getting ignored and nothing gets written to nginx.conf.

proxy:  # Optional -- Configure Proxy
  buffer_size: 4k  # Optional
  buffering: true  # Optional boolean
  buffers:  # Optional
    number: 8  # Required
    size: 4k  # Required
  busy_buffers_size: 8k  # Optional
  cache: false  # Optional -- Set to 'false' or specify cache zone

@alessfg
Copy link
Collaborator

alessfg commented Mar 22, 2021

You might want to update to Jinja2 2.11.x and see if that addresses any of your errors. Re proxy, there's a typo under defaults/main/template.yml. You should include your proxy details under nginx_config_http_template. I'll create a separate PR to address that asap. When in doubt, the molecule tests are always a good source of truth and should always be fully functional.

@ghomem
Copy link
Author

ghomem commented Mar 22, 2021

I opened a separate issue for the proxy: problem above to not spam this one.

@JKetelaar
Copy link

JKetelaar commented Apr 16, 2021

Having the same issue in regards of http/gzip.j2. Tried upgrading to Jinja2==2.11.3, but that hasn't helped either.
This is the config:

---
nginx_config_main_template:
  http_settings:
    gzip:
      enable: true
      buffers:
        number: 32
        size: 16k
      comp_level: 6
      vary: true
      proxied:
      - any
      types:
      - "*"

Error:

    "msg": "AnsibleUndefinedVariable: the inline if-expression on line 27 in 'http/gzip.j2' evaluated to false and no else section was defined.",

@alessfg
Copy link
Collaborator

alessfg commented Apr 16, 2021

Line 27 includes the proxied template. Can you try running the example here https://github.com/nginxinc/ansible-role-nginx-config/blob/main/molecule/default/converge.yml#L62-L76 and seeing if you still run into any issues? That will help determine whether it's an issue with the role or perchance it's still a Jinja2 issue (maybe Jinja2 didn't update correctly?).

@rhaamo
Copy link

rhaamo commented Aug 25, 2021

I did ran into that proxied issue, doing a pip install --upgrade Jinja2 upgraded from 2.10.1 to 3.0.1 and the issue isn't present on next run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants