2019-11-03 14:43:45 +00:00
|
|
|
---
|
2020-03-15 10:52:29 +00:00
|
|
|
- name: Set SSH port
|
|
|
|
set_fact:
|
|
|
|
ansible_port: "{{SSH_PORT}}"
|
|
|
|
|
|
|
|
|
2019-12-23 15:08:34 +00:00
|
|
|
- name: check if HAProxy is installed
|
2019-11-28 16:39:24 +00:00
|
|
|
package_facts:
|
|
|
|
manager: "auto"
|
|
|
|
|
2019-12-15 07:41:24 +00:00
|
|
|
|
|
|
|
- name: populate service facts
|
|
|
|
service_facts:
|
2019-12-30 15:52:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
- name: install EPEL Repository
|
|
|
|
yum:
|
|
|
|
name: epel-release
|
|
|
|
state: latest
|
2020-09-23 03:57:26 +00:00
|
|
|
disable_gpg_check: yes
|
2019-12-30 15:52:01 +00:00
|
|
|
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and HAPVER|length > 0
|
|
|
|
ignore_errors: yes
|
|
|
|
environment:
|
|
|
|
http_proxy: "{{PROXY}}"
|
|
|
|
https_proxy: "{{PROXY}}"
|
2019-12-15 07:41:24 +00:00
|
|
|
|
2019-11-06 15:15:41 +00:00
|
|
|
|
2019-12-30 16:41:16 +00:00
|
|
|
- name: install HAProxy {{HAPVER}} on EL{{ansible_facts['distribution_major_version']}}
|
2019-11-03 14:43:45 +00:00
|
|
|
yum:
|
|
|
|
name:
|
2021-07-21 04:57:58 +00:00
|
|
|
- http://repo.roxy-wi.org/haproxy-{{HAPVER}}.el{{ansible_facts['distribution_major_version']}}.x86_64.rpm
|
2019-11-03 14:43:45 +00:00
|
|
|
- socat
|
2020-12-15 06:34:02 +00:00
|
|
|
- rsyslog
|
2019-11-03 14:43:45 +00:00
|
|
|
state: present
|
2020-09-23 03:57:26 +00:00
|
|
|
disable_gpg_check: yes
|
2019-12-30 16:41:16 +00:00
|
|
|
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and HAPVER|length > 0
|
2020-04-25 11:06:20 +00:00
|
|
|
ignore_errors: yes
|
2019-11-06 15:15:41 +00:00
|
|
|
register: install_result
|
2019-11-03 14:43:45 +00:00
|
|
|
environment:
|
|
|
|
http_proxy: "{{PROXY}}"
|
|
|
|
https_proxy: "{{PROXY}}"
|
|
|
|
|
|
|
|
|
2020-04-25 11:06:20 +00:00
|
|
|
- name: Try to install another HAProxy {{HAPVER}} on EL{{ansible_facts['distribution_major_version']}}
|
|
|
|
yum:
|
|
|
|
name:
|
2021-07-21 04:57:58 +00:00
|
|
|
- http://repo1.roxy-wi.org/haproxy-{{HAPVER}}.el{{ansible_facts['distribution_major_version']}}.x86_64.rpm
|
2020-04-25 11:06:20 +00:00
|
|
|
- socat
|
2020-12-15 06:34:02 +00:00
|
|
|
- rsyslog
|
2021-03-04 05:53:27 +00:00
|
|
|
- bind-utils
|
2020-04-25 11:06:20 +00:00
|
|
|
state: present
|
|
|
|
register: install_result1
|
|
|
|
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and ("'timed out' in install_result.stderr")
|
|
|
|
ignore_errors: yes
|
|
|
|
environment:
|
|
|
|
http_proxy: "{{PROXY}}"
|
|
|
|
https_proxy: "{{PROXY}}"
|
|
|
|
|
|
|
|
|
2019-11-03 14:43:45 +00:00
|
|
|
- name: set_fact from wi`
|
|
|
|
set_fact:
|
|
|
|
haproxy_from_wi: "yes"
|
2019-12-30 16:41:16 +00:00
|
|
|
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and HAPVER|length > 0
|
2019-11-03 14:43:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
- name: install the latest version of HAProxy
|
|
|
|
yum:
|
|
|
|
name:
|
|
|
|
- haproxy
|
|
|
|
- socat
|
2020-12-15 06:34:02 +00:00
|
|
|
- rsyslog
|
2019-11-03 14:43:45 +00:00
|
|
|
state: latest
|
2020-04-25 11:06:20 +00:00
|
|
|
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and ("'FAILED' in install_result1.stderr")
|
2019-11-03 14:43:45 +00:00
|
|
|
environment:
|
|
|
|
http_proxy: "{{PROXY}}"
|
|
|
|
https_proxy: "{{PROXY}}"
|
|
|
|
|
|
|
|
|
|
|
|
- name: Install HAProxy
|
|
|
|
apt:
|
|
|
|
name:
|
|
|
|
- haproxy
|
|
|
|
- socat
|
2020-12-15 06:34:02 +00:00
|
|
|
- rsyslog
|
2019-11-03 14:43:45 +00:00
|
|
|
state: present
|
|
|
|
when: ansible_facts['os_family'] == 'Debian' or ansible_facts['os_family'] == 'Ubuntu'
|
|
|
|
environment:
|
|
|
|
http_proxy: "{{PROXY}}"
|
|
|
|
https_proxy: "{{PROXY}}"
|
|
|
|
|
|
|
|
|
2019-11-28 16:39:24 +00:00
|
|
|
- name: Change wrong HAProxy service file
|
|
|
|
template:
|
|
|
|
src: haproxy.service.j2
|
|
|
|
dest: /usr/lib/systemd/system/haproxy.service
|
|
|
|
mode: 0644
|
|
|
|
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and haproxy_from_wi is defined
|
|
|
|
|
2020-04-05 10:08:15 +00:00
|
|
|
|
|
|
|
- name: test to see if selinux is running
|
|
|
|
command: getenforce
|
|
|
|
register: sestatus
|
2021-04-14 12:59:23 +00:00
|
|
|
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS')
|
2020-04-05 10:08:15 +00:00
|
|
|
changed_when: false
|
2021-04-14 12:59:23 +00:00
|
|
|
ignore_errors: yes
|
|
|
|
debugger: never
|
2020-04-05 10:08:15 +00:00
|
|
|
|
|
|
|
|
2020-03-17 18:20:59 +00:00
|
|
|
- name: Disble SELINUX in config
|
2020-03-23 18:56:09 +00:00
|
|
|
template:
|
|
|
|
src: selinux.j2
|
|
|
|
dest: /etc/selinux/config
|
2020-03-24 09:45:44 +00:00
|
|
|
ignore_errors: yes
|
2021-08-03 06:30:47 +00:00
|
|
|
when:
|
|
|
|
- sestatus.stdout is defined
|
|
|
|
- '"Enforcing" in sestatus.stdout'
|
2020-03-24 10:03:37 +00:00
|
|
|
|
2020-03-17 18:20:59 +00:00
|
|
|
|
|
|
|
- name: Disble SELINUX in env
|
2020-04-05 10:08:15 +00:00
|
|
|
shell: setenforce 0 &> /dev/null
|
2020-03-24 09:45:44 +00:00
|
|
|
ignore_errors: yes
|
2020-03-24 13:00:09 +00:00
|
|
|
debugger: never
|
2021-08-03 06:30:47 +00:00
|
|
|
when:
|
|
|
|
- sestatus.stdout is defined
|
|
|
|
- '"Enforcing" in sestatus.stdout'
|
2020-04-05 10:08:15 +00:00
|
|
|
|
2020-03-17 18:20:59 +00:00
|
|
|
|
2019-11-28 16:39:24 +00:00
|
|
|
- name: Enable and start service HAProxy
|
|
|
|
systemd:
|
|
|
|
name: haproxy
|
|
|
|
daemon_reload: yes
|
|
|
|
state: started
|
|
|
|
enabled: yes
|
|
|
|
force: no
|
|
|
|
ignore_errors: yes
|
|
|
|
when: "'haproxy' in ansible_facts.packages"
|
|
|
|
|
|
|
|
|
|
|
|
- name: Exiting
|
|
|
|
meta: end_play
|
|
|
|
when: "'haproxy' in ansible_facts.packages"
|
|
|
|
|
|
|
|
|
2020-04-05 10:08:15 +00:00
|
|
|
- name: Installing HAProxy conf for rsyslog
|
|
|
|
template:
|
|
|
|
src: haproxy_rsyslog.conf.j2
|
|
|
|
dest: /etc/rsyslog.d/haproxy.conf
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
|
|
|
|
- name: Installing rsyslog config
|
|
|
|
template:
|
|
|
|
src: rsyslog.conf
|
|
|
|
dest: /etc/rsyslog.conf
|
|
|
|
ignore_errors: yes
|
|
|
|
notify: restart rsyslog
|
2020-12-15 06:34:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
- name: Installing HAProxy conf for logrotate
|
|
|
|
template:
|
|
|
|
src: logrotate.conf.j2
|
|
|
|
dest: /etc/logrotate.d/haproxy.conf
|
|
|
|
ignore_errors: yes
|
2020-04-05 10:08:15 +00:00
|
|
|
|
|
|
|
|
2019-11-03 14:43:45 +00:00
|
|
|
- name: Get HAProxy version.
|
|
|
|
command: haproxy -v
|
|
|
|
register: haproxy_version_result
|
|
|
|
changed_when: false
|
|
|
|
check_mode: false
|
|
|
|
|
2019-11-28 16:39:24 +00:00
|
|
|
|
2019-11-03 14:43:45 +00:00
|
|
|
- name: Set HAProxy version.
|
|
|
|
set_fact:
|
|
|
|
haproxy_version: "{{ '1.5' if '1.5.' in haproxy_version_result.stdout else '1.6' }}"
|
2019-11-28 16:39:24 +00:00
|
|
|
|
2019-12-15 07:41:24 +00:00
|
|
|
|
|
|
|
- name: Open stat port for firewalld
|
|
|
|
firewalld:
|
|
|
|
port: "{{ item }}/tcp"
|
|
|
|
state: enabled
|
|
|
|
permanent: yes
|
|
|
|
immediate: yes
|
|
|
|
ignore_errors: yes
|
2020-03-18 19:03:19 +00:00
|
|
|
no_log: True
|
2020-03-24 13:00:09 +00:00
|
|
|
debugger: never
|
2021-03-04 05:53:27 +00:00
|
|
|
when:
|
|
|
|
- '"firewalld" in ansible_facts.packages'
|
|
|
|
- ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS'
|
|
|
|
- ansible_facts.services["firewalld.service"]['state'] == "running"
|
2019-12-15 07:41:24 +00:00
|
|
|
with_items: [ "{{ STAT_PORT }}", "{{ SOCK_PORT }}" ]
|
|
|
|
|
|
|
|
|
|
|
|
- name: Open stat port for iptables
|
|
|
|
iptables:
|
|
|
|
chain: INPUT
|
|
|
|
destination_port: "{{ item }}"
|
|
|
|
jump: ACCEPT
|
|
|
|
protocol: tcp
|
|
|
|
ignore_errors: yes
|
|
|
|
with_items: [ "{{ STAT_PORT }}", "{{ SOCK_PORT }}" ]
|
|
|
|
|
2019-11-03 14:43:45 +00:00
|
|
|
|
|
|
|
- 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
|
2020-11-05 17:16:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
- name: Creates HAProxy stats directory
|
|
|
|
file:
|
|
|
|
path: /var/lib/haproxy
|
|
|
|
owner: haproxy
|
|
|
|
group: haproxy
|
|
|
|
state: directory
|
|
|
|
ignore_errors: yes
|
|
|
|
|
2019-11-03 14:43:45 +00:00
|
|
|
|
|
|
|
- name: Enable and start service HAProxy
|
2019-11-06 15:15:41 +00:00
|
|
|
systemd:
|
2019-11-03 14:43:45 +00:00
|
|
|
name: haproxy
|
|
|
|
daemon_reload: yes
|
|
|
|
state: started
|
|
|
|
enabled: yes
|
2019-11-06 15:15:41 +00:00
|
|
|
force: no
|
2019-11-03 14:43:45 +00:00
|
|
|
ignore_errors: yes
|
|
|
|
|
2019-11-28 16:39:24 +00:00
|
|
|
|
2019-11-06 15:15:41 +00:00
|
|
|
- name: Add syn_flood tasks
|
|
|
|
include: syn_flood.yml
|
|
|
|
when: (SYN_FLOOD is defined) and (SYN_FLOOD|length > 0)
|
2019-11-28 16:39:24 +00:00
|
|
|
|