0

我正在努力在我的领事模板中嵌套环境变量以获得所需的结果。关于如何实现这一点的任何想法?

  template {
    data = <<EOH
  {{ with secret "cluster/ca/issue/nomad-my-role" "common_name=socat.service.consul" "ip_sans=127.0.0.1" "alt_names={{ env "attr.unique.hostname" }}.node.primary.consul" "ip_sans={{ env "attr.unique.network.ip-address" }}" }}
  {{- .Data.certificate -}}
  {{ end }}
  EOH
    destination   = "local/certificate.crt"
    change_mode   = "restart"
  }
4

1 回答 1

1

任何有兴趣的人的解决方案

  template {
    data = <<EOH
  {{$host := env "attr.unique.hostname"}}
  {{$hostStr := printf "alt_names=%s.node.primary.consul" $host}}
  {{$ip := env "attr.unique.network.ip-address"}}
  {{$ipStr := printf "ip_sans=127.0.0.1,%s" $ip}}

  {{ with secret "cluster/ca/issue/nomad-my-role" "common_name=socat.service.consul" $ipStr $hostStr }}
  {{- .Data.certificate -}}
  {{ end }}
  EOH
    destination   = "local/certificate.crt"
    change_mode   = "restart"
  }
于 2019-11-13T00:47:22.850 回答