Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template{} don't have access to nomad task environment (and interpolation keys) #1979

Closed
jippi opened this issue Nov 11, 2016 · 8 comments
Closed

Comments

@jippi
Copy link
Contributor

jippi commented Nov 11, 2016

I've discussed this a few times with @dadgar , but couldn't find any ticket on the issue, so creating one.

Today the template{} environment do not got access to any of the nomad interpolation values like ${NOMAD_ALLOC_INDEX} or ${NOMAD_PORT_label}, which for me - and many others based on the gitter activity - is both surprising and severely limiting the usefulness and ease of setting up in-container configuration without this nomad context.

I would expect accessing these keys would be {{env "NOMAD_ALLOC_INDEX"}} as per the usual CT docs on env access

I'm fully aware @dadgar wanted this in 0.5.0, but due to the complexity of the task, it didn't make it, so here's hoping for the feature getting into 0.5.1.

The technical issue, as far as I understand, is that consul-template, embedded in nomad, does not support injecting of arbitrary ENV keys programatically yet.

I assume consul-template logic would be expanded to take a dictionary of env() to the runner and have https://github.com/hashicorp/consul-template/blob/4836d07af372ff9f705a5013dfc534f110621223/template/template_functions.go#L467-L470 look up in that dictionary as well?

@jippi jippi changed the title consul-template don't have access to nomad task environment (and interpolation keys) template{} don't have access to nomad task environment (and interpolation keys) Nov 11, 2016
@momania
Copy link

momania commented Jan 3, 2017

Is this going to be available in an upcoming 0.5.x release? It is a key missing link to be able to source environment agnostic templates as task artifacts as there is no way to tell the template engine from which environment store to source the template replacements.

@jippi
Copy link
Contributor Author

jippi commented Jan 3, 2017

@momania they are working on this as we speak, its a pretty big change internally to how template{} and consul-template works - there is afaik no official stance on 0.5 or 0.6 will be the release to include this improvement :)

@dadgar
Copy link
Contributor

dadgar commented Jan 3, 2017

@momania As @jippi mentioned it is being worked on right now! This is part of a reliability/refactor work happening and at the end of that the code base will allow us to pass env vars to consul-template. So it is a matter of when it gets done and what release we are on. I am optimistic that it will be in a 0.5.x cut!

@momania
Copy link

momania commented Jan 3, 2017

That's great news! Thanks!

@rogeti
Copy link

rogeti commented Jun 29, 2017

If I understand correclty, this should work now, correct? If so, can someone please provide an example of calling a nomad interpolation key.

I have tried using something like Hostname = server-${NOMAD_ALLOC_INDEX} and hostname = server-{{env "NOMAD_ALLOC_INDEX"}}, but when running either through consul-template I either get the literal text printed back (using ${KEY}) or nothing (using {{env "KEY"}}. Buy nothing I mean consul-tempalte returns server- .

@jippi
Copy link
Contributor Author

jippi commented Jun 29, 2017

https://www.nomadproject.io/docs/job-specification/template.html got that covered?

spoiler: {{ env "NOMAD_ALLOC_INDEX" }}

@rogeti
Copy link

rogeti commented Jun 29, 2017

Wow... big derp on my part, I glossed right over that part of the docs.

  • Thank you!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants