salt: require_in formula cannot extend ID error

Description of Issue/Question

I have an include on an external formula and require its execution to happen after the execution of some other state:

include:
  - nginx.ng

download-openresty-more-headers:
  archive.extracted:
    - name: /tmp/
    - source: https://github.com/openresty/headers-more-nginx-module/archive/v{{ openresty_headers_more['version'] 
}}.tar.gz
    - source_hash: sha256={{ openresty_headers_more['hash'] }}
    - archive_format: tar
    - if_missing: /tmp/openresty_headers_more-{{ openresty_headers_more['version'] }}.tar.gz

rename-openresty-more-headers:
  file.rename:
    - name: /tmp/headers-more-nginx-module
    - source: /tmp/headers-more-nginx-module-{{ openresty_headers_more['version'] }}
    - require:
      - archive: download-openresty-more-headers
      - sls: nginx.ng

The following SLS file works, but the relationship on the require is the incorrect and I need to inverse the dependency such that nginx.ng requires the rename-openresty-more-headers state:

include:
  - nginx.ng

download-openresty-more-headers:
  archive.extracted:
    - name: /tmp/
    - source: https://github.com/openresty/headers-more-nginx-module/archive/v{{ openresty_headers_more['version'] 
}}.tar.gz
    - source_hash: sha256={{ openresty_headers_more['hash'] }}
    - archive_format: tar
    - if_missing: /tmp/openresty_headers_more-{{ openresty_headers_more['version'] }}.tar.gz

rename-openresty-more-headers:
  file.rename:
    - name: /tmp/headers-more-nginx-module
    - source: /tmp/headers-more-nginx-module-{{ openresty_headers_more['version'] }}
    - require:
      - archive: download-openresty-more-headers
    - require_in:
      - sls: nginx.ng

However, this results in the following error (which I understand from the docs should work as require_in is just the inverse of require):

local:
    Data failed to compile:
----------
    Cannot extend ID 'nginx.ng' in 'base:bc-nginx'. It is not part of the high state.
This is likely due to a missing include statement or an incorrectly typed ID.
Ensure that a state with an ID of 'nginx.ng' is available
in environment 'base' and to SLS 'bc-nginx'

Versions Report

Salt Version:
           Salt: 2015.8.8.2

Dependency Versions:
         Jinja2: 2.7.3
       M2Crypto: Not Installed
           Mako: Not Installed
         PyYAML: 3.11
          PyZMQ: 14.4.0
         Python: 2.7.9 (default, Mar  1 2015, 12:57:24)
           RAET: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.2
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
        libgit2: Not Installed
        libnacl: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.2
   mysql-python: 1.2.3
      pycparser: Not Installed
       pycrypto: 2.6.1
         pygit2: Not Installed
   python-gnupg: Not Installed
          smmap: Not Installed
        timelib: Not Installed

System Versions:
           dist: debian 8.4 
        machine: x86_64
        release: 3.16.0-4-amd64
         system: debian 8.4

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 15 (7 by maintainers)

Most upvoted comments

@Ch3LL that’s correct. The require_in ordering is (if I’ve understand it correctly from the docs) not applied when I have it on the sls state file, but it is applied when I have it on some arbitrary state within the state file.

@Ch3LL Thanks for taking the time to investigate this issue! When I add a state to end ngin/ng/init.sls it fixes the error message:

extend:
  nginx_service:
    service:
      - watch:
        - file: nginx_config
      - require:
        - file: nginx_config
  nginx_config:
    file:
      - require:
        {% if nginx.install_from_source %}
        - cmd: nginx_install
        {% else %}
        - pkg: nginx_install
        {% endif %}

nginx_test: 
  cmd.run:
    - name: /usr/sbin/nginx -t

However the ordering of state execution is still incorrect because nginx.ng executes before download-openresty-more-headers and rename-openresty-more-headers states:

include:
  - nginx.ng

download-openresty-more-headers:
  archive.extracted:
    - name: /tmp/
    - source: https://github.com/openresty/headers-more-nginx-module/archive/v{{ openresty_headers_more['version'] 
}}.tar.gz
    - source_hash: sha256={{ openresty_headers_more['hash'] }}
    - archive_format: tar
    - if_missing: /tmp/openresty_headers_more-{{ openresty_headers_more['version'] }}.tar.gz
    - require_in:
      - sls: nginx.ng

rename-openresty-more-headers:
  file.symlink:
    - name: /tmp/headers-more-nginx-module
    - target: /tmp/headers-more-nginx-module-{{ openresty_headers_more['version'] }}
    - require_in:
      - sls: nginx.ng

What is interesting is that if I change the require_in from the nginx.ng state file to some named state within the nginx formula (i.e. nginx_configure) then it works as intended:

include:
  - nginx.ng
download-openresty-more-headers:
  archive.extracted:
    - name: /tmp/
    - source: https://github.com/openresty/headers-more-nginx-module/archive/v{{ openresty_headers_more['version'] 
}}.tar.gz
    - source_hash: sha256={{ openresty_headers_more['hash'] }}
    - archive_format: tar
    - if_missing: /tmp/openresty_headers_more-{{ openresty_headers_more['version'] }}.tar.gz
    - require_in:
      - cmd: nginx_configure
rename-openresty-more-headers:
  file.symlink:
    - name: /tmp/headers-more-nginx-module
    - target: /tmp/headers-more-nginx-module-{{ openresty_headers_more['version'] }}
    - require_in:
      - cmd: nginx_configure

I wonder if this could also be a bug?