main.yml 904 B

1234567891011121314151617181920212223242526272829303132
  1. ---
  2. - name: Ensure HAProxy is installed.
  3. package: name=haproxy state=present
  4. - name: Ensure HAProxy is enabled (so init script will start it on Debian).
  5. lineinfile:
  6. dest: /etc/default/haproxy
  7. regexp: "^ENABLED.+$"
  8. line: "ENABLED=1"
  9. state: present
  10. when: ansible_os_family == 'Debian'
  11. - name: Get HAProxy version.
  12. command: haproxy -v
  13. register: haproxy_version_result
  14. changed_when: false
  15. check_mode: false
  16. - name: Set HAProxy version.
  17. set_fact:
  18. haproxy_version: '{{ haproxy_version_result.stdout_lines[0] | regex_replace("^HA-?Proxy version (\d+(\.\d+)*).*$", "\1") }}'
  19. - name: Copy HAProxy configuration in place.
  20. template:
  21. src: haproxy.cfg.j2
  22. dest: /etc/haproxy/haproxy.cfg
  23. mode: 0644
  24. validate: haproxy -f %s -c -q
  25. notify: restart haproxy
  26. - name: Ensure HAProxy is started and enabled on boot.
  27. service: name=haproxy state=started enabled=yes