【问题标题】:nesting env vars in consul template在领事模板中嵌套环境变量
【发布时间】:2019-11-12 15:27:33
【问题描述】:

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

  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"
  }

【问题讨论】:

    标签: consul-template


    【解决方案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"
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-03
      • 1970-01-01
      • 1970-01-01
      • 2021-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多