hashicorp / hashicorp/consul-template

Haproxy configuration is blank

Open
#1,167 1 comment 0 reactions 0 assignees View on GitHub
bug unreproducible
Dominant language
Go
Stars
4.8k
Forks
801
Avg merge
4h 5m
Merged PRs (30d)
6

Description

Hi,

I have the following template:

```
]# cat template.tmpl

# HTTP Frontends
frontend http
mode http
bind 0.0.0.0:80
option httplog

{{range ls "marathon"}}
{{with $root := .}}{{with $app := parseJSON $root.Value}}{{with $tasks := ls (printf "marathon/%s/tasks" $root.Key)}}
{{if eq (print $app.labels.HAPROXY_HTTP) "true"}}
# {{$root.Key}} ACLs
{{range $index, $port := $app.ports}}{{with $localName := index $app.labels (printf "HTTP_PORT_IDX_%d_NAME" $index)}}
acl host_{{$localName}} hdr_beg(host) -i {{$localName}}
{{if and (eq (print $app.labels.HTTP_PATH) "true") $app.labels.HTTP_PATH_URL $app.labels.HTTP_PATH_URI}}
acl host_{{printf $app.labels.HTTP_PATH_URL}} path_beg -i {{printf $app.labels.HTTP_PATH_URI}}
use_backend {{printf $app.labels.HTTP_PATH_URL}}_backend if host_{{$localName}} host_{{printf $app.labels.HTTP_PATH_URL}}
{{else}}
use_backend {{$localName}}_backend if host_{{$localName}}
{{end}}
{{else}}
# no HTTP forwarding information for {{$port}}
{{end}}{{end}}
{{end}}
{{else}}
# no tasks for {{$root.Key}}, not generating any HTTP ACLs
{{end}}{{else}}{{end}}{{end}}{{/* end of with $root, $app, and $tasks */}}
{{end}}{{/* end of range "marathon" */}}
```

Consul Config Dir
```
]# cat config/consul.cfg
consul = "xx.xx.xx.xx:8500"
]# cat config/haproxy.cfg
template {
source = "/temp/consul-template/template.tmpl"
destination = "/temp/consul-template/haproxy.cfg"
}
```

Here is the command to run Consul-template

```
./consul-template -config /temp/consul-template/config -log-level info -wait 2s:10s
```

And this the log generated ( info and debug level)

INFO
```
2019/01/17 10:04:14 [INFO] consul-template v0.14.0
2019/01/17 10:04:14 [INFO] (runner) creating new runner (dry: false, once: false)
2019/01/17 10:04:14 [INFO] (runner) creating consul/api client
2019/01/17 10:04:14 [INFO] (runner) creating vault/api client
2019/01/17 10:04:14 [INFO] (runner) creating Watcher
2019/01/17 10:04:14 [INFO] (runner) starting
2019/01/17 10:04:14 [INFO] (runner) running
2019/01/17 10:04:14 [INFO] (runner) was not watching 2 dependencies
2019/01/17 10:04:14 [INFO] (watcher) adding "storeKeyPrefix(marathon)"
2019/01/17 10:04:14 [INFO] (watcher) adding "storeKeyPrefix(marathon)"
2019/01/17 10:04:14 [INFO] (runner) diffing and updating dependencies
2019/01/17 10:04:14 [INFO] (runner) watching 1 dependencies
2019/01/17 10:04:14 [INFO] (view) "storeKeyPrefix(marathon)" received data
2019/01/17 10:04:14 [INFO] (runner) running
2019/01/17 10:04:14 [INFO] (runner) was not watching 8 dependencies
2019/01/17 10:04:14 [INFO] (watcher) adding "storeKeyPrefix(marathon/xxx-test-apps-sampleapptest/tasks)"
2019/01/17 10:04:14 [INFO] (watcher) adding "storeKeyPrefix(marathon/xxx-test-apps-test-cerebro/tasks)"
2019/01/17 10:04:14 [INFO] (watcher) adding "storeKeyPrefix(marathon/mesos-marathon-consul/tasks)"
2019/01/17 10:04:14 [INFO] (watcher) adding "storeKeyPrefix(marathon/xxx-haproxy-https/tasks)"
2019/01/17 10:04:14 [INFO] (watcher) adding "storeKeyPrefix(marathon/xxx-test-apps-test-cerebro/tasks)"
2019/01/17 10:04:14 [INFO] (watcher) adding "storeKeyPrefix(marathon/mesos-marathon-consul/tasks)"
2019/01/17 10:04:14 [INFO] (watcher) adding "storeKeyPrefix(marathon/xxx-haproxy-https/tasks)"
2019/01/17 10:04:14 [INFO] (watcher) adding "storeKeyPrefix(marathon/xxx-test-apps-sampleapptest/tasks)"
2019/01/17 10:04:14 [INFO] (runner) diffing and updating dependencies
2019/01/17 10:04:14 [INFO] (runner) watching 5 dependencies
2019/01/17 10:04:14 [INFO] (view) "storeKeyPrefix(marathon/xxx-haproxy-https/tasks)" received data
2019/01/17 10:04:14 [INFO] (runner) running
2019/01/17 10:04:14 [INFO] (view) "storeKeyPrefix(marathon/mesos-marathon-consul/tasks)" received data
2019/01/17 10:04:14 [INFO] (view) "storeKeyPrefix(marathon/xxx-test-apps-test-cerebro/tasks)" received data
2019/01/17 10:04:14 [INFO] (view) "storeKeyPrefix(marathon/xxx-test-apps-sampleapptest/tasks)" received data
2019/01/17 10:04:14 [INFO] (runner) missing data for 3 dependencies
2019/01/17 10:04:14 [INFO] (runner) diffing and updating dependencies
2019/01/17 10:04:14 [INFO] (runner) watching 5 dependencies
2019/01/17 10:04:14 [INFO] (runner) running
2019/01/17 10:04:14 [INFO] (runner) diffing and updating dependencies
2019/01/17 10:04:14 [INFO] (runner) watching 5 dependencies
```

DEBUG
```
2019/01/17 10:05:13 [INFO] (runner) creating consul/api client
2019/01/17 10:05:13 [DEBUG] (runner) setting consul address to xx.xx.xx.xx:8500
2019/01/17 10:05:13 [INFO] (runner) creating vault/api client
2019/01/17 10:05:13 [DEBUG] (runner) enabling vault SSL
2019/01/17 10:05:13 [INFO] (runner) creating Watcher
2019/01/17 10:05:13 [INFO] (runner) starting
2019/01/17 10:05:13 [DEBUG] (runner) running initial templates
2019/01/17 10:05:13 [INFO] (runner) running
2019/01/17 10:05:13 [DEBUG] (runner) checking template /temp/consul-template/template.tmpl
2019/01/17 10:05:13 [INFO] (runner) was not watching 2 dependencies
2019/01/17 10:05:13 [INFO] (watcher) adding "storeKeyPrefix(marathon)"
2019/01/17 10:05:13 [DEBUG] (watcher) "storeKeyPrefix(marathon)" starting
2019/01/17 10:05:13 [INFO] (watcher) adding "storeKeyPrefix(marathon)"
2019/01/17 10:05:13 [DEBUG] (watcher) "storeKeyPrefix(marathon)" already exists, skipping
2019/01/17 10:05:13 [INFO] (runner) diffing and updating dependencies
2019/01/17 10:05:13 [INFO] (runner) watching 1 dependencies
2019/01/17 10:05:13 [DEBUG] (view) "storeKeyPrefix(marathon)" starting fetch
2019/01/17 10:05:13 [DEBUG] ("storeKeyPrefix(marathon)") querying consul with &{Datacenter: AllowStale:true RequireConsistent:false WaitIndex:0 WaitTime:1m0s Token: Near:}
2019/01/17 10:05:13 [DEBUG] ("storeKeyPrefix(marathon)") Consul returned 9 key pairs
2019/01/17 10:05:13 [INFO] (view) "storeKeyPrefix(marathon)" received data
2019/01/17 10:05:13 [DEBUG] (view) "storeKeyPrefix(marathon)" starting fetch
2019/01/17 10:05:13 [DEBUG] ("storeKeyPrefix(marathon)") querying consul with &{Datacenter: AllowStale:true RequireConsistent:false WaitIndex:212907 WaitTime:1m0s Token: Near:}
2019/01/17 10:05:13 [DEBUG] (runner) receiving dependency "storeKeyPrefix(marathon)"
2019/01/17 10:05:13 [INFO] (runner) running
2019/01/17 10:05:13 [DEBUG] (runner) checking template /temp/consul-template/template.tmpl
2019/01/17 10:05:13 [INFO] (runner) was not watching 8 dependencies
2019/01/17 10:05:13 [INFO] (watcher) adding "storeKeyPrefix(marathon/mesos-marathon-consul/tasks)"
2019/01/17 10:05:13 [DEBUG] (watcher) "storeKeyPrefix(marathon/mesos-marathon-consul/tasks)" starting
2019/01/17 10:05:13 [INFO] (watcher) adding "storeKeyPrefix(marathon/xxx-haproxy-https/tasks)"
2019/01/17 10:05:13 [DEBUG] (watcher) "storeKeyPrefix(marathon/xxx-haproxy-https/tasks)" starting
2019/01/17 10:05:13 [INFO] (watcher) adding "storeKeyPrefix(marathon/xxx-test-apps-sampleapptest/tasks)"
2019/01/17 10:05:13 [DEBUG] (watcher) "storeKeyPrefix(marathon/xxx-test-apps-sampleapptest/tasks)" starting
2019/01/17 10:05:13 [INFO] (watcher) adding "storeKeyPrefix(marathon/xxx-test-apps-test-cerebro/tasks)"
2019/01/17 10:05:13 [DEBUG] (watcher) "storeKeyPrefix(marathon/xxxx-test-apps-test-cerebro/tasks)" starting
2019/01/17 10:05:13 [INFO] (watcher) adding "storeKeyPrefix(marathon/xxx-test-apps-sampleapptest/tasks)"
2019/01/17 10:05:13 [DEBUG] (watcher) "storeKeyPrefix(marathon/xxx-test-apps-sampleapptest/tasks)" already exists, skipping
2019/01/17 10:05:13 [DEBUG] (view) "storeKeyPrefix(marathon/mesos-marathon-consul/tasks)" starting fetch
2019/01/17 10:05:13 [DEBUG] (view) "storeKeyPrefix(marathon/xxx-test-apps-test-cerebro/tasks)" starting fetch
2019/01/17 10:05:13 [DEBUG] (view) "storeKeyPrefix(marathon/xxx-haproxy-https/tasks)" starting fetch
2019/01/17 10:05:13 [DEBUG] ("storeKeyPrefix(marathon/mesos-marathon-consul/tasks)") querying consul with &{Datacenter: AllowStale:true RequireConsistent:false WaitIndex:0 WaitTime:1m0s Token: Near:}
2019/01/17 10:05:13 [DEBUG] ("storeKeyPrefix(marathon/xxx-test-apps-test-cerebro/tasks)") querying consul with &{Datacenter: AllowStale:true RequireConsistent:false WaitIndex:0 WaitTime:1m0s Token: Near:}
2019/01/17 10:05:13 [INFO] (watcher) adding "storeKeyPrefix(marathon/xxx-test-apps-test-cerebro/tasks)"
2019/01/17 10:05:13 [DEBUG] ("storeKeyPrefix(marathon/xxx-haproxy-https/tasks)") querying consul with &{Datacenter: AllowStale:true RequireConsistent:false WaitIndex:0 WaitTime:1m0s Token: Near:}
2019/01/17 10:05:13 [DEBUG] (watcher) "storeKeyPrefix(marathon/xxx-test-apps-test-cerebro/tasks)" already exists, skipping
2019/01/17 10:05:13 [INFO] (watcher) adding "storeKeyPrefix(marathon/mesos-marathon-consul/tasks)"
2019/01/17 10:05:13 [DEBUG] (watcher) "storeKeyPrefix(marathon/mesos-marathon-consul/tasks)" already exists, skipping
2019/01/17 10:05:13 [INFO] (watcher) adding "storeKeyPrefix(marathon/xxx-haproxy-https/tasks)"
2019/01/17 10:05:13 [DEBUG] (watcher) "storeKeyPrefix(marathon/xxx-haproxy-https/tasks)" already exists, skipping
2019/01/17 10:05:13 [INFO] (runner) diffing and updating dependencies
2019/01/17 10:05:13 [DEBUG] (runner) "storeKeyPrefix(marathon)" is still needed
2019/01/17 10:05:13 [INFO] (runner) watching 5 dependencies
2019/01/17 10:05:13 [DEBUG] (view) "storeKeyPrefix(marathon/xxx-test-apps-sampleapptest/tasks)" starting fetch
2019/01/17 10:05:13 [DEBUG] ("storeKeyPrefix(marathon/xxx-test-apps-sampleapptest/tasks)") querying consul with &{Datacenter: AllowStale:true RequireConsistent:false WaitIndex:0 WaitTime:1m0s Token: Near:}
2019/01/17 10:05:13 [DEBUG] ("storeKeyPrefix(marathon/xxx-haproxy-https/tasks)") Consul returned 1 key pairs
2019/01/17 10:05:13 [INFO] (view) "storeKeyPrefix(marathon/xxx-haproxy-https/tasks)" received data
2019/01/17 10:05:13 [DEBUG] (view) "storeKeyPrefix(marathon/xxx-haproxy-https/tasks)" starting fetch
2019/01/17 10:05:13 [DEBUG] ("storeKeyPrefix(marathon/mesos-marathon-consul/tasks)") Consul returned 1 key pairs
2019/01/17 10:05:13 [INFO] (view) "storeKeyPrefix(marathon/mesos-marathon-consul/tasks)" received data
2019/01/17 10:05:13 [DEBUG] (view) "storeKeyPrefix(marathon/mesos-marathon-consul/tasks)" starting fetch
2019/01/17 10:05:13 [DEBUG] ("storeKeyPrefix(marathon/xxx-test-apps-test-cerebro/tasks)") Consul returned 1 key pairs
2019/01/17 10:05:13 [INFO] (view) "storeKeyPrefix(marathon/xxx-test-apps-test-cerebro/tasks)" received data
2019/01/17 10:05:13 [DEBUG] (view) "storeKeyPrefix(marathon/xxx-test-apps-test-cerebro/tasks)" starting fetch
2019/01/17 10:05:13 [DEBUG] ("storeKeyPrefix(marathon/mesos-marathon-consul/tasks)") querying consul with &{Datacenter: AllowStale:true RequireConsistent:false WaitIndex:210734 WaitTime:1m0s Token: Near:}
2019/01/17 10:05:13 [DEBUG] ("storeKeyPrefix(marathon/xxx-test-apps-sampleapptest/tasks)") Consul returned 2 key pairs
2019/01/17 10:05:13 [INFO] (view) "storeKeyPrefix(marathon/xxx-test-apps-sampleapptest/tasks)" received data
2019/01/17 10:05:13 [DEBUG] ("storeKeyPrefix(marathon/xxx-test-apps-test-cerebro/tasks)") querying consul with &{Datacenter: AllowStale:true RequireConsistent:false WaitIndex:210730 WaitTime:1m0s Token: Near:}
2019/01/17 10:05:13 [DEBUG] (view) "storeKeyPrefix(marathon/xxx-test-apps-sampleapptest/tasks)" starting fetch
2019/01/17 10:05:13 [DEBUG] ("storeKeyPrefix(marathon/xxx-haproxy-https/tasks)") querying consul with &{Datacenter: AllowStale:true RequireConsistent:false WaitIndex:212907 WaitTime:1m0s Token: Near:}
2019/01/17 10:05:13 [DEBUG] ("storeKeyPrefix(marathon/xxx-test-apps-sampleapptest/tasks)") querying consul with &{Datacenter: AllowStale:true RequireConsistent:false WaitIndex:212797 WaitTime:1m0s Token: Near:}
2019/01/17 10:05:13 [DEBUG] (runner) receiving dependency "storeKeyPrefix(marathon/xxx-haproxy-https/tasks)"
2019/01/17 10:05:13 [DEBUG] (runner) receiving dependency "storeKeyPrefix(marathon/mesos-marathon-consul/tasks)"
2019/01/17 10:05:13 [DEBUG] (runner) receiving dependency "storeKeyPrefix(marathon/xxx-test-apps-test-cerebro/tasks)"
2019/01/17 10:05:13 [DEBUG] (runner) receiving dependency "storeKeyPrefix(marathon/xxx-test-apps-sampleapptest/tasks)"
2019/01/17 10:05:13 [INFO] (runner) running
2019/01/17 10:05:13 [DEBUG] (runner) checking template /temp/consul-template/template.tmpl
2019/01/17 10:05:13 [DEBUG] (runner) checking ctemplate &{Source:/temp/consul-template/template.tmpl Destination:/temp/consul-template/haproxy.cfg Command: CommandTimeout:30s Perms:-rw-r--r-- Backup:false}
2019/01/17 10:05:13 [DEBUG] (runner) wouldRender: true, didRender: false
2019/01/17 10:05:13 [INFO] (runner) diffing and updating dependencies
2019/01/17 10:05:13 [DEBUG] (runner) "storeKeyPrefix(marathon/xxx-test-apps-sampleapptest/tasks)" is still needed
2019/01/17 10:05:13 [DEBUG] (runner) "storeKeyPrefix(marathon/xxx-test-apps-test-cerebro/tasks)" is still needed
2019/01/17 10:05:13 [DEBUG] (runner) "storeKeyPrefix(marathon/mesos-marathon-consul/tasks)" is still needed
2019/01/17 10:05:13 [DEBUG] (runner) "storeKeyPrefix(marathon)" is still needed
2019/01/17 10:05:13 [DEBUG] (runner) "storeKeyPrefix(marathon/xxx-haproxy-https/tasks)" is still needed
2019/01/17 10:05:13 [INFO] (runner) watching 5 dependencies
```

The haproxy.cfg is coming blank

## Consul Template version
consul-template v0.14.0
## Consul Version
Consul v0.8.3
## Marathon Version
1.7.X

## Actual behavior
```
It should create one ACL and corresponding Backend entry in haproxy.cfg
(One of the app has this Marathon label true HAPROXY_HTTP)
```

Please assist and let me know if you need any other info from my side.

Thanks
Rahul

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the blank output with template.tmpl, config/consul.cfg, config/haproxy.cfg, and the shown consul-template command. Compare the rendered file with the Consul keys and the INFO/DEBUG dependency logs; done means identifying why the HAProxy configuration is empty and verifying the corrected output.

Written by the indexing model from the issue text.

Assessment

Domain
devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.