Open baby-gnu opened 3 years ago
I see only 2 differences between with context
and without context
:
tplroot
defined in the .sls
is visble in the imported filetplfile
is different
with context
set tplfile
to the .sls
file doing the importwithout context
set tplfile
to the imported fileAs an example, here is my setup:
Thanks @noelmcloughlin for the review.
I see no formula using ../map.jinja
but near all of them use with context
, so may not be so easily automated with ssf-formula
:thinking:
I see some map.jinja
settings in ssf-formula
so it may not be that hard, like for the cert-formula.
I think this would break our workflow. We have many formulas and we want to use a single version of tofs for all of them rather than including the file in all of the formulas. This significantly reduces duplication.
The directory tree is something like:
$ tree
.
├── ssh
│ ├── client.sls
│ ├── files
│ │ ├── default
│ │ │ └── etc
│ │ │ └── ssh
│ │ │ └── ssh_known_hosts.tmpl
│ │ └── MacOS
│ │ └── etc
│ │ └── ssh
│ │ ├── ssh_config.tmpl
│ │ └── sshd_config.tmpl
│ ├── init.sls
│ ├── keys.sls
│ ├── known_hosts.sls
│ ├── parameters
│ │ ├── defaults.yaml
│ │ └── os_family
│ │ ├── MacOS.yaml
│ │ └── Windows.yaml
│ ├── pillar.example
│ └── server.sls
└── _tofs
├── libmapstack.jinja
├── libmatchers.jinja
├── libsaltcli.jinja
├── libtofs.jinja
├── map.jinja
└── README.md
# cat ssh/client.sls
{%- from "_tofs/libtofs.jinja" import files_switch with context %}
{%- from "_tofs/map.jinja" import mapdata with context %}
ssh_config:
file.managed:
- name: {{ mapdata['filename'] }}
- source: {{ files_switch(
["/etc/ssh/ssh_config.tmpl"],
lookup="ssh_config",
)
}}
- user: root
- group: wheel
- mode: "0644"
- template: jinja
By importing with context we can keep the tofs files in a different directory and it still correctly finds the tplroot of the formula. I haven't tested this change, but if it forces imports "without context" then I believe our setup will break.
The tofs files are supposed to be considered "library" files, so I think it would be silly to make them function based on their location rather than the location of the file doing the import. Alternatively, someone could just supply a "without context" if they want that (incredibly weird) functionality.
PR progress checklist (to be filled in by reviewers)
What type of PR is this?
Primary type
[build]
Changes related to the build system[chore]
Changes to the build process or auxiliary tools and libraries such as documentation generation[ci]
Changes to the continuous integration configuration[feat]
A new feature[fix]
A bug fix[perf]
A code change that improves performance[refactor]
A code change that neither fixes a bug nor adds a feature[revert]
A change used to revert a previous commit[style]
Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)Secondary type
[docs]
Documentation changes[test]
Adding missing or correcting existing testsDoes this PR introduce a
BREAKING CHANGE
?Yes.
BREAKING CHANGE:
map.jinja
import must usewithout context
BREAKING CHANGE:
libmapstack.jinja
import must usewithout context
BREAKING CHANGE:
libmatchers.jinja
import must usewithout context
Related issues and/or pull requests
saltstack-formulas/apache-formula#295 saltstack-formulas/cert-formula#37
Describe the changes you're proposing
tplroot
can't be set correctly when the import:with context
In this case, the
tpldir
is set to the directory of the importer.sls
file instead of the.jinja
imported one.We force the
without context
which permits to directly usetpldir
as thetplroot
which is the directory of the imported file.Pillar / config required to test the proposed changes
Debug log showing how the proposed changes work
Documentation checklist
README
(e.g.Available states
).pillar.example
.Testing checklist
state_top
).Additional context