Hi, I am new to Nomad and trying to figure out how can I make a use of variables in Nomad using template and I am struggling to figure out how that can be achieved.
Here is my partial job specification which uses template write variable in a ${NOMAD_SECRETS_DIR}
and access it as environment variable
template {
destination = "${NOMAD_SECRETS_DIR}/env.vars"
env = true
data = <<EOH
{{ range nomadVarList "nomad/jobs@arch-team" }}
{{ . }}
{{ end }}
EOH
}
Where arch-team
is the namespace in which variables are created as seen below
Here are my two variables
Here is my job specification where I am trying to access those variables (role_id
and temp_environment
) in env
stanza.
job "email-api" {
datacenters = ["dc1"]
node_pool = "rhel-8x"
namespace = "arch-team"
group "api" {
scaling {
min = 1
max = 10
enabled = true
}
update {
max_parallel = 3
health_check = "checks"
min_healthy_time = "10s"
healthy_deadline = "5m"
progress_deadline = "10m"
auto_revert = true
auto_promote = true
canary = 1
stagger = "30s"
}
spread {
attribute = "${node.unique.id}"
}
network {
port "http"{
to = 80
}
}
service {
name = "emailhandler-api"
port = "http"
}
template {
destination = "${NOMAD_SECRETS_DIR}/env.vars"
env = true
data = <<EOH
{{ range nomadVarList "nomad/jobs@arch-team" }}
{{ . }}
{{ end }}
EOH
}
env {
environment = "${NOMAD_PORT_http}"
NODE_IP = "${NOMAD_IP_http}"
ASPNETCORE_ENVIRONMENT = "${temp_environment}"
HashiVaultRoleId_arch = "${role_id}"
}
driver = "docker"
config {
image = "myregistry/emailhandler.webapi:0.1.22"
ports = ["http"]
force_pull = true
}
}
}
}
I exported $NOMAD_TOKEN
which is really a management token… When I plan and run job, it just waits and then fails.
I just don’t know how to check what might have happened while trying to get those variables.
Is there anything I need to do to read these variables? As I mentioned, I am running job using my nomad_token which is a management token.
Also if someone can tell me how to access the detailed logs of a job I submitted. I tried nomad alloc logs <allocation_id>
but it only prints logs that my job writes on console. I don’t see any logs from Nomad.
I will appreciate help in this regards. I am struggling from last couple of days with this.