consul模板的说明2

保证模板的正常执行 使用||true

$ consul-template -template "in.ctmpl:out.file:service nginx restart || true"

当nginx不返回0的时候,仍然返回OK exit code, consul模板仍然作为服务继续执行。

建议复杂的东西还是写sh吧。

多阶段执行

{{range services}}

{{range service .Name}}

{{.Address}}

{{end}}{{end}}

注意执行的顺序, 试试各种不同的逻辑。会有惊喜呦。 (有可能前面没执行完,就执行后面的逻辑了)

帮助函数

除了上面写的service之类的基本函数,还有辅助类函数 如bykey,bytag,toJSON,contains ,in,join,divide,add等函数可以用。

原文地址:https://www.cnblogs.com/wang2650/p/5527489.html