Consul-template if else 条件

Consul-template if else condition

我有以下领事模板。

{{ range service "mysql_slave.mysql" "any" }}
host_name                      {{.Node}}
command                        check_nrpe!check_procs_1
{{end}}

我想添加如果我的主机名匹配 "database-1" 然后命令 "check_procs_1" 和其他命令 "check_procs_2"

输出

host_name                      node_server
command                        check_nrpe!check_procs_2

host_name                      database-1
command                        check_nrpe!check_procs_1

host_name                      webserver
command                        check_nrpe!check_procs_2

要解决此问题,我们可以使用以下修复程序。

{{ range service "mysql_slave.mysql" "any" }}

  {{ if eq .Node "database-1" }}

  host_name                      {{.Node}}
  command                        check_nrpe!check_procs_1

  {{else}}

  host_name                      {{.Node}}
  command                        check_nrpe!check_procs_2

  {{end}}

{{end}}