Skip to content

Instantly share code, notes, and snippets.

@jkordish
Last active June 13, 2017 20:17
Show Gist options
  • Save jkordish/141a2a841f78594a7b597a0d12a1da4b to your computer and use it in GitHub Desktop.
Save jkordish/141a2a841f78594a7b597a0d12a1da4b to your computer and use it in GitHub Desktop.
consul-template for generating /etc/hosts from service catalog
# consul-template generated
127.0.0.1 localhost {{with node}}{{.Node.Node}}{{end}}
{{with node}}{{.Node.Address}} {{.Node.Node}}{{end}}
::1 localhost
# hosts by service
{{range services}}}# {{.Name}}{{$Name :=.Name}}{{range $index, $service := service .Name "any" }}
{{.Address}} {{.Node}} {{$Name}}0{{$index | add 1}}
{{end}}{{end}}
# hosts by nodes
{{range nodes}}{{with node .Node}}#{{.Node.Address}} {{.Node.Node}}{{end}}
{{end}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment