Skip to content

Instantly share code, notes, and snippets.

@kenjiskywalker
Created January 22, 2015 14:07
Show Gist options
  • Save kenjiskywalker/d5d219ca1feacf113492 to your computer and use it in GitHub Desktop.
Save kenjiskywalker/d5d219ca1feacf113492 to your computer and use it in GitHub Desktop.
consul
  • command ./consul-template_0.6.0_linux_amd64/consul-template -consul 127.0.0.1:8500 -template "/etc/hosts.ctmpl:/etc/hosts:service dnsmasq restart &"

  • /etc/hosts.ctmpl

# node{{ range nodes }}
{{.Address}} {{.Node}}{{ end }}

# service{{range $tag, $services := service "echo" | byTag}}
{{range $services}}{{.Address}} {{$tag}}.{{.Name}}{{end}}{{end}}
  • /etc/hosts
# node
192.0.2.201 test-consul01
192.0.2.202 test-consul02

# service
192.0.2.201 master.echo
192.0.2.202 slave.echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment