| 1234567891011121314151617181920212223242526272829303132 |
- ---
- - name: Ensure HAProxy is installed.
- package: name=haproxy state=present
- - name: Ensure HAProxy is enabled (so init script will start it on Debian).
- lineinfile:
- dest: /etc/default/haproxy
- regexp: "^ENABLED.+$"
- line: "ENABLED=1"
- state: present
- when: ansible_os_family == 'Debian'
- - name: Get HAProxy version.
- command: haproxy -v
- register: haproxy_version_result
- changed_when: false
- check_mode: false
- - name: Set HAProxy version.
- set_fact:
- haproxy_version: '{{ haproxy_version_result.stdout_lines[0] | regex_replace("^HA-?Proxy version (\d+(\.\d+)*).*$", "\1") }}'
- - name: Copy HAProxy configuration in place.
- template:
- src: haproxy.cfg.j2
- dest: /etc/haproxy/haproxy.cfg
- mode: 0644
- validate: haproxy -f %s -c -q
- notify: restart haproxy
- - name: Ensure HAProxy is started and enabled on boot.
- service: name=haproxy state=started enabled=yes
|