Hello, I have question about template in separate file.
I have many jobs (150+) with this template:
job "example-app" {
datacenters = ["dc1"]
type = "service"
group "web" {
count = 1
task "server" {
driver = "docker"
.....
template {
data = <<-EOF
{{ with secret "kv/data/openobserve" }}
OPENOBSERVE_ADDRESS = "http://openobserve.service.consul:5080"
OPENOBSERVE_USERNAME = "{{ .Data.data.OPENOBSERVE_USERNAME }}"
OPENOBSERVE_PASSWORD = "{{ .Data.data.OPENOBSERVE_PASSWORD }}"
OPENOBSERVE_ORGANIZATION_NAME = "default"
OPENOBSERVE_SERVICE_NAME = {{env "NOMAD_JOB_NAME"}}
{{ end }}
EOF
destination = "task.env"
change_mode = "restart"
env = true
}
.....
Sometimes I need to change this template in all jobs
- add or delete some test envs.
Ideal solution for me - in all jobs put the link for the file with variables. Desired structure of the folder:
nomad
|jobs
|emails
|email-notify.nomad
|kafka
|kafka.nomad
|envs
|db.env.tpl
|kafka.env.tpl
|redis.env.tpl
Or more simply (job and envs in the same folder but not desired):
nomad
|jobs
|emails
|email-notify.nomad
|kafka.env.tpl
|redis.env.tpl
In documentation I found this:
job "docs" {
group "example" {
task "server" {
template {
source = "local/redis.conf.tpl"
destination = "local/redis.conf"
change_mode = "signal"
change_signal = "SIGINT"
}
}
}
}
I can’t understand - is source = "local/redis.conf.tpl"my local path or in the container?
I guess that in the container because got error:
Task hook failed: template: failed to read template: exit status 1: failed to open source file "/server/vars.env": open /server/vars.env: no such file or directory
So I don’t understand how to send my vars template to container.
In docs found Remote template
This example uses an
artifactblock to download an input template before passing it to the template engine:
artifact {
source = "https://example.com/file.yml.tpl"
destination = "local/file.yml.tpl"
}
template {
source = "local/file.yml.tpl"
destination = "local/file.yml"
}
But my env file is near my job! I don’t want to do web server for this …![]()