-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] use of tpldir variable does not allow the formula to be wrapped #295
Comments
Interesting point. I must admit that I always extend formulas by providing new sls under the same With the following fileserver_backend:
- roots
- gitfs I can create I'll make some try tomorrow and post my finding. |
It took a little bit longer but I finally made little tests with relative imports and it's not trivial:
So, To make my test, I created the following files:
Here are the outputs:
This could be solved if we find a consistent way to find the path of the current included/imported file instead of current
Is there a way to achive this consistently across salt versions? I'm a bit lost about what is possible or not [1], [2] :-/ @myii: do you have any hint? Regards. |
I made a little test:
The Inspec The load with context is only useful when the imported
I think we could say that |
I made more tests and I think this solution may be interesting: {#- Make sure `map.jinja` is imported without the context #}
{#- Import `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 %}
{#- `tplroot` is `tpldir`: the directory where is `map.jinja` #}
{%- set tplroot = tpldir %} It's working with v5 This means that for the above example, I must remove all the I could even add another test and raise in {%- if tplfile.startswith("../") %}
{{ raise("Import error: map.jinja must be imported with absolute path. tplfile='" ~ tplfile ~ "'") }}
{%- endif %} This will permit to load |
tpldir does not work with older versions. for example it does not work Salt Version 3000.6
This is a big issue for non zero-day admins |
Hello @kritzi-at, that's strange because I tested on all supported platforms with a test bed
I use kitchen files from template-formula with minor changes for this pseudo formula: test-tplvars-formula/kitchen.yml file# -*- coding: utf-8 -*-
# vim: ft=yaml
---
# For help on this file's format, see https://kitchen.ci/
driver:
name: docker
use_sudo: false
privileged: true
run_command: /lib/systemd/systemd
# Make sure the platforms listed below match up with
# the `env.matrix` instances defined in `.travis.yml`
platforms:
## SALT `tiamat`
- name: debian-10-tiamat-py3
driver:
image: saltimages/salt-tiamat-py3:debian-10
- name: debian-9-tiamat-py3
driver:
image: saltimages/salt-tiamat-py3:debian-9
- name: ubuntu-2004-tiamat-py3
driver:
image: saltimages/salt-tiamat-py3:ubuntu-20.04
- name: ubuntu-1804-tiamat-py3
driver:
image: saltimages/salt-tiamat-py3:ubuntu-18.04
- name: ubuntu-1604-tiamat-py3
driver:
image: saltimages/salt-tiamat-py3:ubuntu-16.04
- name: centos-8-tiamat-py3
driver:
image: saltimages/salt-tiamat-py3:centos-8
- name: centos-7-tiamat-py3
driver:
image: saltimages/salt-tiamat-py3:centos-7
- name: amazonlinux-2-tiamat-py3
driver:
image: saltimages/salt-tiamat-py3:amazonlinux-2
- name: oraclelinux-8-tiamat-py3
driver:
image: saltimages/salt-tiamat-py3:oraclelinux-8
- name: oraclelinux-7-tiamat-py3
driver:
image: saltimages/salt-tiamat-py3:oraclelinux-7
## SALT `master`
- name: debian-10-master-py3
driver:
image: saltimages/salt-master-py3:debian-10
- name: ubuntu-2004-master-py3
driver:
image: saltimages/salt-master-py3:ubuntu-20.04
- name: ubuntu-1804-master-py3
driver:
image: saltimages/salt-master-py3:ubuntu-18.04
- name: centos-8-master-py3
driver:
image: saltimages/salt-master-py3:centos-8
- name: fedora-32-master-py3
driver:
image: saltimages/salt-master-py3:fedora-32
- name: fedora-31-master-py3
driver:
image: saltimages/salt-master-py3:fedora-31
- name: opensuse-leap-152-master-py3
driver:
image: saltimages/salt-master-py3:opensuse-leap-15.2
run_command: /usr/lib/systemd/systemd
# Workaround to avoid intermittent failures on `opensuse-leap-15.2`:
# => SCP did not finish successfully (255): (Net::SCP::Error)
transport:
max_ssh_sessions: 1
- name: amazonlinux-2-master-py3
driver:
image: saltimages/salt-master-py3:amazonlinux-2
- name: gentoo-stage3-latest-master-py3
driver:
image: saltimages/salt-master-py3:gentoo-stage3-latest
run_command: /sbin/init
- name: gentoo-stage3-systemd-master-py3
driver:
image: saltimages/salt-master-py3:gentoo-stage3-systemd
## SALT `3001`
- name: debian-10-3001-py3
driver:
image: saltimages/salt-3001-py3:debian-10
- name: debian-9-3001-py3
driver:
image: saltimages/salt-3001-py3:debian-9
- name: ubuntu-2004-3001-py3
driver:
image: saltimages/salt-3001-py3:ubuntu-20.04
- name: ubuntu-1804-3001-py3
driver:
image: saltimages/salt-3001-py3:ubuntu-18.04
- name: centos-8-3001-py3
driver:
image: saltimages/salt-3001-py3:centos-8
- name: centos-7-3001-py3
driver:
image: saltimages/salt-3001-py3:centos-7
- name: fedora-32-3001-py3
driver:
image: saltimages/salt-3001-py3:fedora-32
- name: fedora-31-3001-py3
driver:
image: saltimages/salt-3001-py3:fedora-31
- name: opensuse-leap-152-3001-py3
driver:
image: saltimages/salt-3001-py3:opensuse-leap-15.2
run_command: /usr/lib/systemd/systemd
# Workaround to avoid intermittent failures on `opensuse-leap-15.2`:
# => SCP did not finish successfully (255): (Net::SCP::Error)
transport:
max_ssh_sessions: 1
- name: amazonlinux-2-3001-py3
driver:
image: saltimages/salt-3001-py3:amazonlinux-2
- name: oraclelinux-8-3001-py3
driver:
image: saltimages/salt-3001-py3:oraclelinux-8
- name: oraclelinux-7-3001-py3
driver:
image: saltimages/salt-3001-py3:oraclelinux-7
- name: gentoo-stage3-latest-3001-py3
driver:
image: saltimages/salt-3001-py3:gentoo-stage3-latest
run_command: /sbin/init
- name: gentoo-stage3-systemd-3001-py3
driver:
image: saltimages/salt-3001-py3:gentoo-stage3-systemd
## SALT `3000.3`
- name: debian-10-3000-3-py3
driver:
image: saltimages/salt-3000.3-py3:debian-10
- name: debian-9-3000-3-py3
driver:
image: saltimages/salt-3000.3-py3:debian-9
- name: ubuntu-1804-3000-3-py3
driver:
image: saltimages/salt-3000.3-py3:ubuntu-18.04
- name: centos-8-3000-3-py3
driver:
image: saltimages/salt-3000.3-py3:centos-8
- name: centos-7-3000-3-py3
driver:
image: saltimages/salt-3000.3-py3:centos-7
- name: fedora-31-3000-3-py3
driver:
image: saltimages/salt-3000.3-py3:fedora-31
- name: opensuse-leap-152-3000-3-py3
driver:
image: saltimages/salt-3000.3-py3:opensuse-leap-15.2
run_command: /usr/lib/systemd/systemd
# Workaround to avoid intermittent failures on `opensuse-leap-15.2`:
# => SCP did not finish successfully (255): (Net::SCP::Error)
transport:
max_ssh_sessions: 1
- name: amazonlinux-2-3000-3-py3
driver:
image: saltimages/salt-3000.3-py3:amazonlinux-2
- name: gentoo-stage3-latest-3000-3-py3
driver:
image: saltimages/salt-3000.3-py3:gentoo-stage3-latest
run_command: /sbin/init
- name: gentoo-stage3-systemd-3000-3-py3
driver:
image: saltimages/salt-3000.3-py3:gentoo-stage3-systemd
- name: ubuntu-1804-3000-3-py2
driver:
image: saltimages/salt-3000.3-py2:ubuntu-18.04
- name: ubuntu-1604-3000-3-py2
driver:
image: saltimages/salt-3000.3-py2:ubuntu-16.04
- name: arch-base-latest-3000-3-py2
driver:
image: saltimages/salt-3000.3-py2:arch-base-latest
run_command: /usr/lib/systemd/systemd
## SALT `2019.2`
- name: centos-6-2019-2-py2
driver:
image: saltimages/salt-2019.2-py2:centos-6
run_command: /sbin/init
- name: amazonlinux-1-2019-2-py2
driver:
image: saltimages/salt-2019.2-py2:amazonlinux-1
run_command: /sbin/init
provisioner:
name: salt_solo
log_level: debug
salt_install: none
require_chef: false
formula: test-tplvars
salt_copy_filter:
- .kitchen
- .git
verifier:
# https://www.inspec.io/
name: inspec
sudo: true
# cli, documentation, html, progress, json, json-min, json-rspec, junit
reporter:
- cli
suites:
- name: default
provisioner:
state_top:
base:
'*':
- test-tplvars.test
verifier:
inspec_tests:
- path: test/integration/default After running ./bin/kitchen list
|
I have now upgraded to salt-minion 3002.2
When i use slsutil.renderer the tpldir seems to be defined, but not as expected:
|
Hello @kritzi-at, can you try a Note that |
Hello @baby-gnu Test script works fine on Ubuntu with minion 3002.2
and on CentOS with minion 3000.6
|
Thanks @kritzi-at, so now I'm wondering why applying Can you explain a little your setup and how you run the formula? |
Hello @baby-gnu, i found the issue. Removing the line fixed everything. |
More tests to see the differences between So, only |
Your setup
Formula commit hash / release tag
starting from e2e1be1
Versions reports (master & minion)
Salt Version:
Salt: 3002.1
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.7.3
docker-py: Not Installed
gitdb: 2.0.6
gitpython: 3.0.7
Jinja2: 2.10.1
libgit2: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.6.2
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: Not Installed
pycryptodome: 3.6.1
pygit2: Not Installed
Python: 3.8.5 (default, Jul 28 2020, 12:59:40)
python-gnupg: 0.4.5
PyYAML: 5.3.1
PyZMQ: 18.1.1
smmap: 2.0.5
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.2
System Versions:
dist: ubuntu 20.04 focal
locale: utf-8
machine: x86_64
release: 5.4.0-52-generic
system: Linux
version: Ubuntu 20.04 focal
Pillar / config used
trying to extend the formula by creating a new www/init.sls and having the contents look like this
{% from "apache/map.jinja" import apache with context %}
include:
apache-config-custom-global:
file.managed:
apache: {{ apache|json }}
gives this error
local:
Data failed to compile:
----------
Rendering SLS 'base:www' failed: Jinja error: www/defaults.yaml
/var/cache/salt/minion/files/base/apache/map.jinja(5):
---
# -- coding: utf-8 --
# vim: ft=jinja
the workaround
{% set curr_tpldir = tpldir %}
{% set tpldir = 'apache' %}
{% from "apache/map.jinja" import apache with context %}
{% set tpldir = curr_tpldir %}
include:
apache-config-custom-global:
file.managed:
apache: {{ apache|json }}
Bug details
Describe the bug
replace the tpldir/tplroot logic with hardcoded apache paths
Steps to reproduce the bug
Expected behaviour
Attempts to fix the bug
Additional context
The text was updated successfully, but these errors were encountered: