saltstack-formulas / nginx-formula

Nginx Salt Formula
http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html
Other
163 stars 421 forks source link

[BUG] nginx.servers and "service_function" error #264

Open vquie opened 4 years ago

vquie commented 4 years ago

Your setup

Formula commit hash / release tag

Commit Hash: a28834207074d7b7796822a83765bec9b799a9f0

Versions reports (master & minion)

minion:

# salt-minion --versions-report
Salt Version:
           Salt: 3000.3

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.7.3
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 2.10
        libgit2: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 3.7.3 (default, Apr  3 2019, 05:39:12)
   python-gnupg: Not Installed
         PyYAML: 3.13
          PyZMQ: 17.1.2
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.3.1

System Versions:
           dist: debian 10.1 
         locale: UTF-8
        machine: x86_64
        release: 4.19.0-6-amd64
         system: Linux
        version: debian 10.1 

master:

# salt-master --versions-report
Salt Version:
           Salt: 3000.3

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.7.3
      docker-py: Not Installed
          gitdb: 2.0.5
      gitpython: 2.1.11
         Jinja2: 2.10
        libgit2: 0.27.7
       M2Crypto: Not Installed
           Mako: 1.1.2
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: 1.3.10
      pycparser: 2.19
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: 0.27.4
         Python: 3.7.3 (default, Apr  3 2019, 05:39:12)
   python-gnupg: Not Installed
         PyYAML: 3.13
          PyZMQ: 17.1.2
          smmap: 2.0.5
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.3.1

System Versions:
           dist: debian 10.1 
         locale: UTF-8
        machine: x86_64
        release: 4.19.0-6-amd64
         system: Linux
        version: debian 10.1 

Bug details

Describe the bug

salt-call state.sls nginx.servers fails with the following error.

local:
    Data failed to compile:
----------
    Rendering SLS 'base:nginx.servers' failed: Jinja variable the template u'nginx/service.sls' (imported on line 8) does not export the requested name 'service_function'

Attempts to fix the bug

Setting service_function in servers.sls directly without importing it, works as expected.

diff --git a/nginx/servers.sls b/nginx/servers.sls
index f3033bb..3dc517d 100644
--- a/nginx/servers.sls
+++ b/nginx/servers.sls
@@ -5,7 +5,8 @@
 {%- set tplroot = tpldir.split('/')[0] %}
 {%- from tplroot ~ '/map.jinja' import nginx, sls_block with context %}
 {%- from tplroot ~ '/servers_config.sls' import server_states with context %}
-{%- from tplroot ~ '/service.sls' import service_function with context %}
+
+{% set service_function = {True:'running', False:'dead'}.get(nginx.service.enable) %}

 {% macro file_requisites(states) %}
       {%- for state in states %}

Additional context

daks commented 4 years ago

Hello,

can you give use more information about how you tested or find this problem? I just tried using the docker image default-debian-10-master-py3 which is a Debian 10 with version 3000-n/a-99ffbf1 of salt and:

Do you have any pillar data you use?