diff --git a/cert/_mapdata/init.sls b/cert/_mapdata/init.sls index 3529a8d..0252877 100644 --- a/cert/_mapdata/init.sls +++ b/cert/_mapdata/init.sls @@ -3,7 +3,7 @@ --- {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split("/")[0] %} -{%- from tplroot ~ "/map.jinja" import mapdata with context %} +{%- from tplroot ~ "/map.jinja" import mapdata without context %} {%- set _mapdata = { "values": mapdata, diff --git a/cert/init.sls b/cert/init.sls index c096a76..5cea1ef 100644 --- a/cert/init.sls +++ b/cert/init.sls @@ -1,6 +1,6 @@ # This is the main state file for deploying certificates -{% from "cert/map.jinja" import mapdata with context %} +{% from "cert/map.jinja" import mapdata without context %} # Install required packages cert_packages: diff --git a/cert/libmapstack.jinja b/cert/libmapstack.jinja index c671c0e..fdbff76 100644 --- a/cert/libmapstack.jinja +++ b/cert/libmapstack.jinja @@ -1,8 +1,19 @@ {#- -*- coding: utf-8 -*- #} {#- vim: ft=jinja #} -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split("/")[0] %} +{#- Force import `without context` #} +{#- `with context` override the `tplfile` and `tpldir` variables #} +{%- if not tplfile.endswith("/libmapstack.jinja") %} +{{ raise("Import error: map.jinja must be imported without context. tplfile='" ~ tplfile ~ "'") }} +{%- endif %} + +{#- Force import with absolute path #} +{%- if tplfile.startswith("../") %} +{{ raise("Import error: map.jinja must be imported with absolute path. tplfile='" ~ tplfile ~ "'") }} +{%- endif %} + +{#- `tplroot` is the directory of the current imported file #} +{%- set tplroot = tpldir %} {%- from tplroot ~ "/libmatchers.jinja" import parse_matchers, query_map %} {%- set _default_config_dirs = [ diff --git a/cert/libmatchers.jinja b/cert/libmatchers.jinja index e9aaed3..ca16c80 100644 --- a/cert/libmatchers.jinja +++ b/cert/libmatchers.jinja @@ -1,8 +1,19 @@ {#- -*- coding: utf-8 -*- #} {#- vim: ft=jinja #} -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split("/")[0] %} +{#- Force import `without context` #} +{#- `with context` override the `tplfile` and `tpldir` variables #} +{%- if not tplfile.endswith("/libmatchers.jinja") %} +{{ raise("Import error: map.jinja must be imported without context. tplfile='" ~ tplfile ~ "'") }} +{%- endif %} + +{#- Force import with absolute path #} +{%- if tplfile.startswith("../") %} +{{ raise("Import error: map.jinja must be imported with absolute path. tplfile='" ~ tplfile ~ "'") }} +{%- endif %} + +{#- `tplroot` is the directory of the current imported file #} +{%- set tplroot = tpldir %} {%- from tplroot ~ "/libsaltcli.jinja" import cli %} {%- set query_map = { diff --git a/cert/map.jinja b/cert/map.jinja index 7340d53..aca0f4e 100644 --- a/cert/map.jinja +++ b/cert/map.jinja @@ -1,8 +1,19 @@ -# -*- coding: utf-8 -*- -# vim: ft=jinja +{#- -*- coding: utf-8 -*- #} +{#- vim: ft=jinja #} -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split("/")[0] %} +{#- Force import `without context` #} +{#- `with context` override the `tplfile` and `tpldir` variables #} +{%- if not tplfile.endswith("/map.jinja") %} +{{ raise("Import error: map.jinja must be imported without context. tplfile='" ~ tplfile ~ "'") }} +{%- endif %} + +{#- Force import with absolute path #} +{%- if tplfile.startswith("../") %} +{{ raise("Import error: map.jinja must be imported with absolute path. tplfile='" ~ tplfile ~ "'") }} +{%- endif %} + +{#- `tplroot` is the directory of the current imported file #} +{%- set tplroot = tpldir %} {%- from tplroot ~ "/libmapstack.jinja" import mapstack %} {#- Where to lookup parameters source files #} diff --git a/test/salt/states/setup-certs-to-remove.sls b/test/salt/states/setup-certs-to-remove.sls index f71b71c..6130eeb 100644 --- a/test/salt/states/setup-certs-to-remove.sls +++ b/test/salt/states/setup-certs-to-remove.sls @@ -4,7 +4,7 @@ # A testing state created to add certificate and key file that will # be removed to test certificate removal. -{% from "cert/map.jinja" import mapdata with context %} +{% from "cert/map.jinja" import mapdata without context %} add-test-cert: file.managed: