Skip to content

Latest commit

 

History

History
27 lines (19 loc) · 1.17 KB

join.md

File metadata and controls

27 lines (19 loc) · 1.17 KB

Joining Structures with Consul Template

Consul Template has built-in support for joining existing arrays and lists on a given separator, but there is no built-in support for complex map-reduce functions. This section details some common join techniques.

Joining Service Addresses

Sometimes you require all service addresses to be listed in a comma-separated list. Memcached and other tools usually accept this as an environment variable.

export MEMCACHED_SERVERS="{{range $index, $service := service "memcached" }}{{if ne $index 0}},{{end}}{{$service.Address}}:{{$service.Port}}{{end}}"

Save this file to disk at a place reachable by the Consul Template process like /tmp/memcached.ctmpl and run Consul Template:

$ consul-template \
  -template="/tmp/memcached.ctmpl:/etc/profile.d/memcached"

Here is an example of what the file may render:

export MEMCACHED_SERVERS="1.2.3.4,5.6.7.8"