interop-workloads/workloads/ansible/shade/lampstack/roles/balancer/tasks/main.yml

41 lines
945 B
YAML
Executable File

---
- name: update apt cache
apt: update_cache=yes
when: ansible_os_family == "Debian"
- name: Haproxy install
package:
name: haproxy
state: latest
- name: Enable haproxy service
replace:
dest: /etc/default/haproxy
regexp: "ENABLED=0"
replace: "ENABLED=1"
backup: no
when: ansible_distribution == 'Ubuntu'
- name: Modify haproxy configuration
blockinfile:
dest: /etc/haproxy/haproxy.cfg
insertafter: EOF
block: |
frontend http-in
bind *:80
default_backend backend_servers
option forwardfor
backend backend_servers
balance roundrobin
- name: Add web servers to the haproxy
lineinfile:
dest: /etc/haproxy/haproxy.cfg
line: " server ws{{ hostvars[item].inter_ip }} {{ hostvars[item].inter_ip }}:80 check"
with_flattened:
- "{{ groups['webservers'] }}"
no_log: True
- service: name=haproxy state=restarted enabled=yes