How do I get from confd the value of the generate key line from etcd
I am using confd and etcd. I am following the confd example for nginx . I put these keys in my etcd service:
curl http://127.0.0.1:4001/v2/keys/myapp/upstream -XPUT -d dir=true
curl http://127.0.0.1:4001/v2/keys/myapp/subdomain -XPUT -d value="myapp"
curl http://127.0.0.1:4001/v2/keys/myapp/upstream/app2 -XPUT -d value="10.0.1.101:80"
curl http://127.0.0.1:4001/v2/keys/myapp/upstream/app1 -XPUT -d value="10.0.1.100:80"
This is my fancy config:
[template]
prefix = "myapp"
keys = [
"subdomain",
"upstream",
]
owner = "nginx"
mode = "0644"
src = "nginx.tmpl"
dest = "/tmp/myapp.conf"
check_cmd = "/usr/sbin/nginx -t -c {{ .src }}"
reload_cmd = "/usr/sbin/service nginx reload"
And this is my tmpl config.
upstream {{.subdomain}} {
{{range $server := .upstream}}
#I want to get the key string value
server {{$sever.key}} {{$server.Value}};
{{end}}
}
server {
server_name {{.subdomain}}.example.com;
location / {
proxy_pass http://{{.subdomain}};
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Here I want to catch the value of a key string like app2 or app1 . I only know how to get his values. I want to do something like this {{$ sever.key}} but it doesn't work. The configuration above {{$ sever.key}} is not correct , but I did it to show what I need.
Is it possible?
Is there any reserverd word for this or syntax?
source to share
I had the same problem. For me this code worked (accepted in your config):
{{range gets "/myapp/upstream/*"}}
server {{base .Key}} {{.Value}}
{{end}}
For me, the main problem was the function gets
. All examples I found on the net have used getvs
which only provides values. Functions base
just remove the first parts of your key's path
See these confd docs for more information .
source to share