Consul-Template - Is there any way to query the current DC

443 views
Skip to first unread message

m...@pagerduty.com

unread,
Aug 29, 2016, 3:48:35 PM8/29/16
to Consul
Hi Folks,

Is there any way in consul-template to identify the datacenter that the template is being rendered in?

Basically, I want to render an HAProxy config file, and I want servers in the local datacenter to be rendered one way, and servers not in the local datacenter to be rendered another way (as backups). I'm good with using {{datacenters}} and looping over the service in each datacenter, but how will I know when I'm in the local datacenter?

Thanks!

mia

Webert de Souza Lima

unread,
Sep 6, 2016, 7:20:57 AM9/6/16
to Consul
You can use Consul Key-Value Store to store the datacenter information and fetch it like you'd fetch it using the template.

Michael Fischer

unread,
Sep 6, 2016, 11:52:20 AM9/6/16
to consu...@googlegroups.com
Alternatively, query Consul before you launch consul-template to fetch the current DC name and store it in an environment variable (e.g. $CONSUL_DC), then then reference it using {{env "CONSUL_DC"}}.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/consul/issues
IRC: #consul on Freenode
---
You received this message because you are subscribed to the Google Groups "Consul" group.
To unsubscribe from this group and stop receiving emails from it, send an email to consul-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/consul-tool/95afc595-22e6-4963-a0f4-e421c1a42faa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages