if statement in Jinja2 templates with Ansible

tasks/main.yml:
- name: configure
  template:
    src: haproxy.cfg.j2
    dest: /etc/haproxy/haproxy.cfg
    owner: root
    group: root
    mode: 0644
  notify: reload haproxy

templates/haproxy.cfg.j2:
...
frontend haproxy
  bind {{ haproxy_listen_addr }}:{{ haproxy_listen_port }}
  mode http
{% if haproxy_stats %}
  stats enable
  stats uri /haproxy?stats
  stats realm HAProxy Statistics
  stats auth admin:admin
{% endif %}
...

defaults/main.yml:
---
haproxy_listen_addr: 0.0.0.0
haproxy_listen_port: 80
haproxy_stats: true