confd newbie试图获取if in template to work"无效类型进行比较"

时间:2016-04-20 15:24:03

标签: docker coreos confd

我导出了一个变量:

export myparam=one

我有模板:file.tmpl:

myproptmpl =
{{ if eq .myparam "one"   }}
    {{ "one" }}
{{ else }}
    {{ "something else" }}
{{ end }}

当我跑confd时,我得到:

# /usr/bin/confd -onetime -backend env
2016-04-20T15:21:58Z 8faae31d53a1 /usr/bin/confd[91]: ERROR template: file.tmpl:70:6: executing "file.tmpl" at <eq .myparam "one">: error calling eq: invalid type for comparison

我是confd的新手。如何将OS环境变量与值进行比较,并根据它们生成不同的结果输出文件?

1 个答案:

答案 0 :(得分:0)

您需要先获取变量然后再进行比较。

例:

myproptmpl =
{{ if eq (getv .myparam) "one" }}
    {{ "one" }}
{{ else }}
    {{ "something else" }}
{{ end }}