领事模板 if else 条件

Kas*_*aka 2 if-statement puppet consul consul-template

我有以下领事模板。

{{ range service "mysql_slave.mysql" "any" }}
host_name                      {{.Node}}
command                        check_nrpe!check_procs_1
{{end}}
Run Code Online (Sandbox Code Playgroud)

我想添加如果我的主机名匹配“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
Run Code Online (Sandbox Code Playgroud)

Kas*_*aka 6

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

{{ 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}}
Run Code Online (Sandbox Code Playgroud)