60 lines
1.5 KiB
YAML
60 lines
1.5 KiB
YAML
|
---
|
||
|
|
||
|
- name: Prepare all nodes
|
||
|
hosts: all
|
||
|
tasks:
|
||
|
- name: Ensure apt cache is updated
|
||
|
ansible.builtin.apt:
|
||
|
update_cache: true
|
||
|
when: ansible_pkg_mgr == 'apt'
|
||
|
|
||
|
- name: Ensure sudo is installed
|
||
|
community.general.apk:
|
||
|
name: sudo
|
||
|
state: present
|
||
|
update_cache: true
|
||
|
when: ansible_pkg_mgr == 'apk'
|
||
|
|
||
|
- name: Prepare Load Balancer
|
||
|
hosts: loadbalancer
|
||
|
tasks:
|
||
|
- name: Ensure HAProxy is installed
|
||
|
ansible.builtin.package:
|
||
|
name: haproxy
|
||
|
state: present
|
||
|
|
||
|
- name: Ensure HAProxy config directory exists
|
||
|
ansible.builtin.file:
|
||
|
path: /usr/local/etc/haproxy
|
||
|
state: directory
|
||
|
mode: 0755
|
||
|
|
||
|
- name: Ensure HAProxy is configured
|
||
|
ansible.builtin.template:
|
||
|
src: haproxy-loadbalancer.conf.j2
|
||
|
dest: /usr/local/etc/haproxy/haproxy.cfg
|
||
|
mode: 0644
|
||
|
|
||
|
- name: Ensure HAProxy service is started
|
||
|
ansible.builtin.command:
|
||
|
cmd: haproxy -D -f /usr/local/etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid
|
||
|
args:
|
||
|
creates: /var/run/haproxy.pid
|
||
|
|
||
|
- name: Prepare nodes
|
||
|
hosts: node*
|
||
|
tasks:
|
||
|
- name: Ensure apt cache is updated and iptables is installed
|
||
|
ansible.builtin.apt:
|
||
|
name: iptables
|
||
|
state: present
|
||
|
update_cache: true
|
||
|
when: ansible_pkg_mgr == 'apt'
|
||
|
|
||
|
- name: Ensure iproute is installed
|
||
|
ansible.builtin.dnf:
|
||
|
name: iproute
|
||
|
state: present
|
||
|
update_cache: true
|
||
|
when: ansible_pkg_mgr == 'dnf'
|