tazjin/kontemplate

path directive doesn't seem to work in yml files

adimarco opened this issue · 3 comments

I recreated the example from the docs with forwarder-asia etc. after I noticed path not seeming to work, and even that example doesn't seem to work (unless I'm missing something)

I've got my forwarders.yml copy/pasted from the example, i.e.:

include:
  - name: forwarder-europe
    path: tools/forwarder
    values:
      source: europe
  - name: forwarder-asia
    path: tools/forwarder
    values:
      source: asia

My directory structure is:

test
├── forwarders.yml
└── tools
    └── forwarder
        └── forwarder.yml

And just to prove the variable substitution works, my tools/forwarder/forwarder.yml is just:

source: {{ .source }}

But, I (sliently) get no output when I run things through kontemplate template like so:

$ kontemplate template test/forwarders.yml 
Loading resources for forwarder-europe
Loading resources for forwarder-asia

If I change that top-level forwarders.yml from the example to remove the path directive and just use the same name for both like so:

include:
  - name: tools/forwarder
    values:
      source: europe
  - name: tools/forwarder
    values:
      source: asia

I get the output I would originally have expected from the example:

$ kontemplate template test/forwarders.yml 
Loading resources for tools/forwarder
Loading resources for tools/forwarder
Rendered file tools/forwarder/forwarder.yml:
source: europe
Rendered file tools/forwarder/forwarder.yml:
source: asia

I've tried several different configurations with this, and they all seem to point back to the path directive just being ignored.

Hey, thanks for reporting this - it does sound odd! I'll investigate.

Could you run kontemplate version and paste the output? (It should contain a git short hash if it's one of my binary releases).

With a setup similar to yours:

vincent@adho /t/path-test> tree
.
├── ctx.yml
└── tools
    └── forwarder
        └── foo.yml

2 directories, 2 files

vincent@adho /t/path-test> cat tools/forwarder/foo.yml
source: {{ .source }}

vincent@adho /t/path-test> cat ctx.yml
---
context: foo
include:
  - name: forwarder-asia
    path: tools/forwarder
    values:
      source: asia
  - name: forwarder-europe
    path: tools/forwarder
    values:
      source: europe

I get the expected output:

vincent@adho /t/path-test> kontemplate version
Kontemplate version 1.2.0 (git commit: f8b6ad6)

vincent@adho /t/path-test> kontemplate template ctx.yml
Loading resources for forwarder-asia
Loading resources for forwarder-europe
Rendered file forwarder-asia/foo.yml:
source: asia

Rendered file forwarder-europe/foo.yml:
source: europe

path overrides were implemented in the most recent release, version 1.2.0.

In previous versions the behaviour would be what you described:

vincent@adho /t/path-test> ./kontemplate version
Kontemplate version 1.1.0 (git commit: f7ce04e)

vincent@adho /t/path-test> ./kontemplate template ctx.yml
Loading resources for forwarder-asia
Loading resources for forwarder-europe

This doesn't fail because the JSON parser does not, by default, fail on extra keys (but it also doesn't do anything with the path value).

My theory is that you may be using a version that does not have this feature yet.


There are two friction-reduction tasks that I want to tackle:

  • Consider adding a key to specify the minimum required kontemplate version on the context file
  • Warn if there actually isn't a folder / there are no files in the folder (the current behaviour of saying "Loading resources ..." and then ... nothing ... feels incorrect)

You are correct, I was using version 1.1.0, which given the release date on 1.2.0 I must have downloaded hours before you released it. I thought I was using the latest version, which explains the perceived documentation mismatch.

1.2.0 works as expected - thanks!