Ansible-role-nginx-config: “AnsibleUndefinedVariable:'http/grpc.j2' 中第 9 行的内联 if 表达式评估为 false,并且没有定义其他部分。”}

创建于 2021-03-22  ·  10评论  ·  资料来源: nginxinc/ansible-role-nginx-config

描述错误

启用 http 部分时无法应用配置。 我收到以下错误:

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

配置已从此示例复制:

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

繁殖

重现行为的步骤:

# 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
[...]

预期行为

我希望配置应用没有错误

您的环境:

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

附加上下文

在此处添加有关该问题的任何其他上下文。

所有10条评论

发现问题。 公关即将到来。

谢谢你的快速反应,我会跟进这个问题的发展。

您可以从 main 中提取并检查最新的 PR 是否解决了您的问题? 您可能需要对模板进行一些进一步的调整,因为自0.3.3以来发生了一些重大变化,但希望分子测试中的更新示例可以帮助您实现目标。

我可以,但我仍在测试其他配置情况。 我刚刚用 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."}

似乎与“代理”行有关。

这是一个更奇怪的错误。 你能检查一下你使用的是哪个版本的 Jinja2 吗? 之前和这个错误的测试都通过得很好,我看到其他人在使用旧版本的 Jinja2 时模板失败。

这是版本:

python3-jinja2 2.10.1-2

我在应用代理时也遇到问题:http_settings 下的部分。 它一直被忽略,并且没有任何内容写入 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

您可能想要更新到 Jinja2 2.11.x并查看是否可以解决您的任何错误。 关于proxydefaults/main/template.yml下有一个错字。 您应该在nginx_config_http_template下包含您的代理详细信息。 我将创建一个单独的 PR 来尽快解决这个问题。 如有疑问,分子测试始终是一个很好的事实来源,并且应该始终功能齐全。

我为代理打开了一个单独的问题:上面的问题不是垃圾邮件。

关于http/gzip.j2有同样的问题。 尝试升级到Jinja2==2.11.3 ,但这也没有帮助。
这是配置:

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

错误:

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

第 27 行包含proxied模板。 您可以尝试在此处运行示例https://github.com/nginxinc/ansible-role-nginx-config/blob/main/molecule/default/converge.yml#L62 -L76 并查看您是否仍然遇到任何问题? 这将有助于确定它是否是角色的问题,或者它仍然是 Jinja2 问题(也许 Jinja2 没有正确更新?)。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

luminouw picture luminouw  ·  4评论

alexsegura picture alexsegura  ·  15评论

ghomem picture ghomem  ·  10评论

VilleMiekkoja picture VilleMiekkoja  ·  13评论

asabhaney picture asabhaney  ·  5评论