This cannot possibly be that difficult, but I cannot figure out how to get the hostname value in a consul (really, vault) template.
The basic problem is that I’m trying to use pkiCert to get a certificate for consul from vault. Since consul needs the certificate before it can talk to the consul server, I can’t use .Node.name - afaik because consul isn’t up yet. I have to use the hostname if that’s what I want for the cert’s CN when I call vault’s .../issue
Some examples have shown using {{ with $host := env "HOSTNAME" }} - which seems to just give me an empty value and others have gone to creating custom go functions within the template itself(?), which I’m struggling to comprehend.
{{ with pkiCert "/pki/issue/node-dot-consul" "common_name=1-2-3-4.node.consul" }}
{{ .Data.Cert }}
{{ end }}
Is it possible to replace 1-2-3-4 with a variable of the hostname in that template code?
I’m a real noob at go templates. where is the documentation for the ‘env’ function you are calling? The only thing I can really find is this https://docs.gomplate.ca/functions/env/ but it doesn’t explain how you are just calling ‘env’ and passing it a value. I know this is probably super simple. Even referencing this template into something like https://gotemplate.io/ is just giving me errors.
Your answer has helped me and I appreciate you taking the tome to post about it!