I have several machines that expose a Syncthing endpoint, which I would like to route through Traefik. The target URL is of the form http://{{ $host }}.funny-name.ts.net:8384
.
I wanted to template the configuration because all are identical, except for the hostname. I tried
{{ define "routers" }}
{{ $host := . }}
syncthing-{{ $host }}:
rule: Host(`{{ $host }}.my-domain.eu`)
service: syncthing-{{ $host }}
{{ end }}
{{ define "services" }}
{{ $host := . }}
syncthing-{{ $host }}:
loadBalancer:
servers:
- url: http://{{ $host }}.funny-name.ts.net:8384
{{ end }}
http:
routers:
{{ template "routers" "aaa" "bbb" }}
services:
{{ template "services" "aaa" "bbb" }}
I was expecting the followig configuration to be generated:
http:
routers:
syncthing-aaa:
rule: Host(`aaa.my-domain.eu`)
service: syncthing-aaa
syncthing-bbb:
rule: Host(`bbb.my-domain.eu`)
service: syncthing-bbb
services:
syncthing-aaa:
loadBalancer:
servers:
- url: http://aaa.funny-name.ts.net:8384
syncthing-bbb:
loadBalancer:
servers:
- url: http://bbb.funny-name.ts.net:8384
What I get instead is an error in the log (as soon as the file is updated)
traefik-1 | 2025-02-21T10:22:05+01:00 ERR Error occurred during watcher callback error="/config/config.d/testemplate.yaml: template: :18:22: executing \"\" at <\"aaa\">: can't give argument to non-function \"aaa\"" providerName=file
traefik-1 | 2025-02-21T10:22:05+01:00 ERR Error occurred during watcher callback error="/config/config.d/testemplate.yaml: template: :18:22: executing \"\" at <\"aaa\">: can't give argument to non-function \"aaa\"" providerName=file
What does this error mean and how to fix my template?