mirror of https://github.com/Aidaho12/haproxy-wi
parent
f981819505
commit
cb03546ca2
|
@ -1,4 +1,3 @@
|
||||||
import logging
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from peewee import fn
|
from peewee import fn
|
||||||
|
|
|
@ -23,12 +23,12 @@ def ssh_command(server_ip: str, commands: list, **kwargs):
|
||||||
stdin, stdout, stderr = ssh.run_command(command, timeout=timeout)
|
stdin, stdout, stderr = ssh.run_command(command, timeout=timeout)
|
||||||
stdin.close()
|
stdin.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
roxywi_common.handle_exceptions(e, server_ip, f'Something wrong with SSH connection. Probably sudo with password', roxywi=1)
|
roxywi_common.handle_exceptions(e, server_ip, 'Something wrong with SSH connection. Probably sudo with password', roxywi=1)
|
||||||
|
|
||||||
if stderr:
|
if stderr:
|
||||||
for line in stderr.readlines():
|
for line in stderr.readlines():
|
||||||
if line:
|
if line:
|
||||||
roxywi_common.handle_exceptions(e, server_ip, line, roxywi=1)
|
roxywi_common.handle_exceptions(line, server_ip, line, roxywi=1)
|
||||||
|
|
||||||
if kwargs.get('raw'):
|
if kwargs.get('raw'):
|
||||||
return stdout.readlines()
|
return stdout.readlines()
|
||||||
|
@ -40,7 +40,7 @@ def ssh_command(server_ip: str, commands: list, **kwargs):
|
||||||
else:
|
else:
|
||||||
return stdout.read().decode(encoding='UTF-8')
|
return stdout.read().decode(encoding='UTF-8')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
roxywi_common.handle_exceptions(e, server_ip, f'Something wrong with SSH connection. Probably sudo with password', roxywi=1)
|
roxywi_common.handle_exceptions(e, server_ip, 'Something wrong with SSH connection. Probably sudo with password', roxywi=1)
|
||||||
|
|
||||||
|
|
||||||
def subprocess_execute(cmd):
|
def subprocess_execute(cmd):
|
||||||
|
|
|
@ -38,7 +38,7 @@ def add_agent(data) -> int:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
inv, server_ips = generate_agent_inc(server_ip, 'install', agent_uuid)
|
inv, server_ips = generate_agent_inc(server_ip, 'install', agent_uuid)
|
||||||
run_ansible(inv, server_ips, f'smon_agent')
|
run_ansible(inv, server_ips, 'smon_agent')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
common_roxywi.handle_exceptions(e, server_ip, 'Cannot install SMON agent', roxywi=1, login=1)
|
common_roxywi.handle_exceptions(e, server_ip, 'Cannot install SMON agent', roxywi=1, login=1)
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ def delete_agent(agent_id: int):
|
||||||
agent_uuid = ''
|
agent_uuid = ''
|
||||||
try:
|
try:
|
||||||
inv, server_ips = generate_agent_inc(server_ip, 'uninstall', agent_uuid)
|
inv, server_ips = generate_agent_inc(server_ip, 'uninstall', agent_uuid)
|
||||||
run_ansible(inv, server_ips, f'smon_agent')
|
run_ansible(inv, server_ips, 'smon_agent')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
common_roxywi.handle_exceptions(e, server_ip, 'error: Cannot uninstall SMON agent', roxywi=1, login=1)
|
common_roxywi.handle_exceptions(e, server_ip, 'error: Cannot uninstall SMON agent', roxywi=1, login=1)
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ def send_get_request_to_agent(agent_id: int, server_ip: str, api_path: str) -> b
|
||||||
headers = get_agent_headers(agent_id)
|
headers = get_agent_headers(agent_id)
|
||||||
agent_port = sql.get_setting('agent_port')
|
agent_port = sql.get_setting('agent_port')
|
||||||
try:
|
try:
|
||||||
req = requests.get(f'http://{server_ip}:{agent_port}/{api_path}', headers=headers)
|
req = requests.get(f'http://{server_ip}:{agent_port}/{api_path}', headers=headers, timeout=5)
|
||||||
return req.content
|
return req.content
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(f'error: Cannot get agent status: {e}')
|
raise Exception(f'error: Cannot get agent status: {e}')
|
||||||
|
@ -97,7 +97,7 @@ def send_post_request_to_agent(agent_id: int, server_ip: str, api_path: str, jso
|
||||||
headers = get_agent_headers(agent_id)
|
headers = get_agent_headers(agent_id)
|
||||||
agent_port = sql.get_setting('agent_port')
|
agent_port = sql.get_setting('agent_port')
|
||||||
try:
|
try:
|
||||||
req = requests.post(f'http://{server_ip}:{agent_port}/{api_path}', headers=headers, json=json_data)
|
req = requests.post(f'http://{server_ip}:{agent_port}/{api_path}', headers=headers, json=json_data, timeout=5)
|
||||||
return req.content
|
return req.content
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(f'error: Cannot get agent status: {e}')
|
raise Exception(f'error: Cannot get agent status: {e}')
|
||||||
|
@ -107,7 +107,7 @@ def delete_check(agent_id: int, server_ip: str, check_id: int) -> bytes:
|
||||||
headers = get_agent_headers(agent_id)
|
headers = get_agent_headers(agent_id)
|
||||||
agent_port = sql.get_setting('agent_port')
|
agent_port = sql.get_setting('agent_port')
|
||||||
try:
|
try:
|
||||||
req = requests.delete(f'http://{server_ip}:{agent_port}/check/{check_id}', headers=headers)
|
req = requests.delete(f'http://{server_ip}:{agent_port}/check/{check_id}', headers=headers, timeout=5)
|
||||||
return req.content
|
return req.content
|
||||||
except requests.exceptions.HTTPError as e:
|
except requests.exceptions.HTTPError as e:
|
||||||
common_roxywi.logging(server_ip, f'error: Cannot delete check from agent: http error {e}', roxywi=1, login=1)
|
common_roxywi.logging(server_ip, f'error: Cannot delete check from agent: http error {e}', roxywi=1, login=1)
|
||||||
|
|
|
@ -3,19 +3,17 @@
|
||||||
src: haproxy.service.j2
|
src: haproxy.service.j2
|
||||||
dest: /usr/lib/systemd/system/haproxy.service
|
dest: /usr/lib/systemd/system/haproxy.service
|
||||||
mode: 0644
|
mode: 0644
|
||||||
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and haproxy_from_wi is defined
|
when: ansible_os_family == "RedHat" and haproxy_from_wi is defined
|
||||||
|
|
||||||
|
|
||||||
- name: test to see if selinux is running
|
- name: test to see if selinux is running
|
||||||
command: getenforce
|
command: getenforce
|
||||||
register: sestatus
|
register: sestatus
|
||||||
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS')
|
when: ansible_os_family == "RedHat"
|
||||||
changed_when: false
|
changed_when: false
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
debugger: never
|
debugger: never
|
||||||
|
|
||||||
|
- name: Disable SELINUX in config
|
||||||
- name: Disble SELINUX in config
|
|
||||||
template:
|
template:
|
||||||
src: selinux.j2
|
src: selinux.j2
|
||||||
dest: /etc/selinux/config
|
dest: /etc/selinux/config
|
||||||
|
@ -24,8 +22,7 @@
|
||||||
- sestatus.stdout is defined
|
- sestatus.stdout is defined
|
||||||
- '"Enforcing" in sestatus.stdout'
|
- '"Enforcing" in sestatus.stdout'
|
||||||
|
|
||||||
|
- name: Disable SELINUX in env
|
||||||
- name: Disble SELINUX in env
|
|
||||||
shell: setenforce 0 &> /dev/null
|
shell: setenforce 0 &> /dev/null
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
debugger: never
|
debugger: never
|
||||||
|
@ -44,7 +41,7 @@
|
||||||
debugger: never
|
debugger: never
|
||||||
when:
|
when:
|
||||||
- '"firewalld" in ansible_facts.packages'
|
- '"firewalld" in ansible_facts.packages'
|
||||||
- ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS'
|
- ansible_os_family == "RedHat"
|
||||||
- ansible_facts.services["firewalld.service"]['state'] == "running"
|
- ansible_facts.services["firewalld.service"]['state'] == "running"
|
||||||
with_items: [ "{{ STAT_PORT }}", "{{ SOCK_PORT }}", "10000" ]
|
with_items: [ "{{ STAT_PORT }}", "{{ SOCK_PORT }}", "10000" ]
|
||||||
|
|
||||||
|
@ -72,6 +69,13 @@
|
||||||
mode: 0644
|
mode: 0644
|
||||||
force: no
|
force: no
|
||||||
|
|
||||||
|
- name: Copy HAProxy state file in place.
|
||||||
|
template:
|
||||||
|
src: haproxy.state.j2
|
||||||
|
dest: /etc/haproxy/haproxy.state
|
||||||
|
mode: 0644
|
||||||
|
force: no
|
||||||
|
|
||||||
- name: Creates HAProxy stats directory
|
- name: Creates HAProxy stats directory
|
||||||
file:
|
file:
|
||||||
path: /var/lib/haproxy
|
path: /var/lib/haproxy
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
name: epel-release
|
name: epel-release
|
||||||
state: latest
|
state: latest
|
||||||
disable_gpg_check: yes
|
disable_gpg_check: yes
|
||||||
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and HAPVER|length > 0
|
when: ansible_os_family == "RedHat" and HAPVER|length > 0
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
environment:
|
environment:
|
||||||
http_proxy: "{{PROXY}}"
|
http_proxy: "{{PROXY}}"
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
- name: Set dist short name if EL
|
- name: Set dist short name if EL
|
||||||
set_fact:
|
set_fact:
|
||||||
distr_short_name: "el"
|
distr_short_name: "el"
|
||||||
when: ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS'
|
when: ansible_os_family == "RedHat"
|
||||||
|
|
||||||
- name: Set dist short name if Amazon Linux
|
- name: Set dist short name if Amazon Linux
|
||||||
set_fact:
|
set_fact:
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
- rsyslog
|
- rsyslog
|
||||||
state: present
|
state: present
|
||||||
disable_gpg_check: yes
|
disable_gpg_check: yes
|
||||||
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and HAPVER|length > 0
|
when: ansible_os_family == "RedHat" and HAPVER|length > 0
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
register: install_result
|
register: install_result
|
||||||
retries: 5
|
retries: 5
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
- rsyslog
|
- rsyslog
|
||||||
- bind-utils
|
- bind-utils
|
||||||
state: present
|
state: present
|
||||||
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and ("'timed out' in install_result.stderr")
|
when: (ansible_os_family == "RedHat") and ("'timed out' in install_result.stderr")
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
register: install_result1
|
register: install_result1
|
||||||
retries: 5
|
retries: 5
|
||||||
|
@ -59,7 +59,7 @@
|
||||||
- name: set_fact from wi
|
- name: set_fact from wi
|
||||||
set_fact:
|
set_fact:
|
||||||
haproxy_from_wi: "yes"
|
haproxy_from_wi: "yes"
|
||||||
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS' or ansible_distribution == 'Amazon') and HAPVER|length > 0
|
when: (ansible_os_family == "RedHat"' or ansible_distribution == 'Amazon') and HAPVER|length > 0
|
||||||
|
|
||||||
|
|
||||||
- name: install the latest version of HAProxy
|
- name: install the latest version of HAProxy
|
||||||
|
@ -69,7 +69,7 @@
|
||||||
- socat
|
- socat
|
||||||
- rsyslog
|
- rsyslog
|
||||||
state: latest
|
state: latest
|
||||||
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and (install_result.rc != 0 and install_result1.rc != 0)
|
when: (ansible_os_family == "RedHat") and (install_result.rc != 0 and install_result1.rc != 0)
|
||||||
register: install_result
|
register: install_result
|
||||||
retries: 5
|
retries: 5
|
||||||
until: install_result.rc == 0
|
until: install_result.rc == 0
|
||||||
|
@ -86,7 +86,7 @@
|
||||||
- socat
|
- socat
|
||||||
- rsyslog
|
- rsyslog
|
||||||
state: present
|
state: present
|
||||||
when: ansible_facts['os_family'] == 'Debian' or ansible_facts['os_family'] == 'Ubuntu'
|
when: ansible_os_family == "Debian"
|
||||||
environment:
|
environment:
|
||||||
http_proxy: "{{PROXY}}"
|
http_proxy: "{{PROXY}}"
|
||||||
https_proxy: "{{PROXY}}"
|
https_proxy: "{{PROXY}}"
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
src: /var/www/haproxy-wi/app/scripts/ansible/roles/haproxy/templates/logrotate.conf.j2
|
src: /var/www/haproxy-wi/app/scripts/ansible/roles/haproxy/templates/logrotate.conf.j2
|
||||||
dest: /etc/logrotate.d/haproxy.conf
|
dest: /etc/logrotate.d/haproxy.conf
|
||||||
force: no
|
force: no
|
||||||
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS')
|
when: ansible_os_family == "RedHat"
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
|
|
||||||
- name: Installing HAProxy conf for logrotate on Debian
|
- name: Installing HAProxy conf for logrotate on Debian
|
||||||
|
@ -19,5 +19,5 @@
|
||||||
src: /var/www/haproxy-wi/app/scripts/ansible/roles/haproxy/templates/logrotate-debian.conf.j2
|
src: /var/www/haproxy-wi/app/scripts/ansible/roles/haproxy/templates/logrotate-debian.conf.j2
|
||||||
dest: /etc/logrotate.d/haproxy-roxy-wi
|
dest: /etc/logrotate.d/haproxy-roxy-wi
|
||||||
force: no
|
force: no
|
||||||
when: (ansible_facts['os_family'] == "Debian" or ansible_facts['os_family'] == 'Ubuntu')
|
when: ansible_os_family == "Debian"
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
1
|
Loading…
Reference in New Issue