my nomad job will run on various machines and will be based on environment variables set in the current environment. I’m trying to solve it with templates (and it’s not working), but I’m open to any suggestions.
@swbs90 thanks for the suggestion but it didn’t help.
@jrasell the env vars are decided by the environment, not by the job. so we want to run the same job file on different environments, and each should get it env vars from the environment itself, not from the job file. That’s why I went with template, I didn’t find how to do it with the env block.
TEST_VAR is just a sample var, I’m just trying to find out how to make it work, then I’ll apply it to the final job file.
Hi @chiptus and thanks for the additional details.
The template block is rendered on the client where the allocation is run and not the local machine where the nomad job run command is executed. This would explain why you are seeing the results and problem you currently have.
In order to achieve the results you are looking for I would use a combination of HCL2 variables and the env block.
The job specification will detail an input variable, and then reference the input within the env block in order to export this to the tasks environment. In order to trigger the job with a custom variable, you can use the nomad job run -var='env_var=my-custom-var' file.nomad
We’re using the API to deploy instead of the cli, and if I understand the code right, variables are only available from the cli. I was hoping for the template stanza to be able to query the current environment to get those env variables.
Thanks again, I’ll continue to explore the options.