- Создана система пресетов для быстрого переключения между конфигурациями - Добавлены пресеты: minimal, standard, docker, cluster - Обновлена структура проекта с папками cicd/, vault/, scripts/ - Упрощена система vault с функциональными секретами - Добавлены скрипты для работы с пресетами - Обновлен Makefile с командами для пресетов - Удалены старые файлы и структуры Автор: Сергей Антропов Сайт: https://devops.org.ru
263 lines
7.1 KiB
YAML
263 lines
7.1 KiB
YAML
---
|
|
# Универсальные проверки для тестового стенда
|
|
# Автор: Сергей Антропов
|
|
# Сайт: https://devops.org.ru
|
|
|
|
- name: Verify web servers
|
|
hosts: web
|
|
become: true
|
|
tasks:
|
|
- name: Check nginx service status
|
|
systemd:
|
|
name: nginx
|
|
register: nginx_status
|
|
|
|
- name: Verify nginx is running
|
|
assert:
|
|
that:
|
|
- nginx_status.status.ActiveState == "active"
|
|
- nginx_status.status.SubState == "running"
|
|
fail_msg: "nginx service is not running"
|
|
success_msg: "nginx service is running"
|
|
|
|
- name: Test nginx response
|
|
uri:
|
|
url: "http://{{ inventory_hostname }}"
|
|
method: GET
|
|
register: nginx_response
|
|
|
|
- name: Verify nginx response
|
|
assert:
|
|
that:
|
|
- nginx_response.status == 200
|
|
fail_msg: "nginx is not responding"
|
|
success_msg: "nginx is responding correctly"
|
|
|
|
- name: Verify app servers
|
|
hosts: app
|
|
become: true
|
|
tasks:
|
|
- name: Check Python installation
|
|
command: python3 --version
|
|
register: python_version
|
|
changed_when: false
|
|
|
|
- name: Verify Python is installed
|
|
assert:
|
|
that:
|
|
- python_version.rc == 0
|
|
fail_msg: "Python3 is not installed"
|
|
success_msg: "Python3 is installed: {{ python_version.stdout }}"
|
|
|
|
- name: Check app file exists
|
|
stat:
|
|
path: /opt/myapp/app.py
|
|
register: app_file
|
|
|
|
- name: Verify app file exists
|
|
assert:
|
|
that:
|
|
- app_file.stat.exists
|
|
fail_msg: "App file does not exist"
|
|
success_msg: "App file exists and is executable"
|
|
|
|
- name: Verify database servers
|
|
hosts: database
|
|
become: true
|
|
tasks:
|
|
- name: Check SQLite installation
|
|
command: sqlite3 --version
|
|
register: sqlite_version
|
|
changed_when: false
|
|
|
|
- name: Verify SQLite is installed
|
|
assert:
|
|
that:
|
|
- sqlite_version.rc == 0
|
|
fail_msg: "SQLite is not installed"
|
|
success_msg: "SQLite is installed: {{ sqlite_version.stdout }}"
|
|
|
|
- name: Check database file exists
|
|
stat:
|
|
path: /var/lib/mydb/sample.db
|
|
register: db_file
|
|
|
|
- name: Verify database file exists
|
|
assert:
|
|
that:
|
|
- db_file.stat.exists
|
|
fail_msg: "Database file does not exist"
|
|
success_msg: "Database file exists"
|
|
|
|
- name: Test database query
|
|
command: sqlite3 /var/lib/mydb/sample.db "SELECT COUNT(*) FROM users;"
|
|
register: db_query
|
|
changed_when: false
|
|
|
|
- name: Verify database query
|
|
assert:
|
|
that:
|
|
- db_query.rc == 0
|
|
- db_query.stdout | int > 0
|
|
fail_msg: "Database query failed"
|
|
success_msg: "Database query successful: {{ db_query.stdout }} users found"
|
|
|
|
- name: Verify cache servers
|
|
hosts: cache
|
|
become: true
|
|
tasks:
|
|
- name: Check Redis service status
|
|
systemd:
|
|
name: redis
|
|
register: redis_status
|
|
|
|
- name: Verify Redis is running
|
|
assert:
|
|
that:
|
|
- redis_status.status.ActiveState == "active"
|
|
- redis_status.status.SubState == "running"
|
|
fail_msg: "Redis service is not running"
|
|
success_msg: "Redis service is running"
|
|
|
|
- name: Test Redis connection
|
|
command: redis-cli ping
|
|
register: redis_ping
|
|
changed_when: false
|
|
|
|
- name: Verify Redis connection
|
|
assert:
|
|
that:
|
|
- redis_ping.rc == 0
|
|
- redis_ping.stdout == "PONG"
|
|
fail_msg: "Redis is not responding"
|
|
success_msg: "Redis is responding correctly"
|
|
|
|
- name: Verify load balancer
|
|
hosts: loadbalancer
|
|
become: true
|
|
tasks:
|
|
- name: Check HAProxy service status
|
|
systemd:
|
|
name: haproxy
|
|
register: haproxy_status
|
|
|
|
- name: Verify HAProxy is running
|
|
assert:
|
|
that:
|
|
- haproxy_status.status.ActiveState == "active"
|
|
- haproxy_status.status.SubState == "running"
|
|
fail_msg: "HAProxy service is not running"
|
|
success_msg: "HAProxy service is running"
|
|
|
|
- name: Check HAProxy configuration
|
|
stat:
|
|
path: /etc/haproxy/haproxy.cfg
|
|
register: haproxy_config
|
|
|
|
- name: Verify HAProxy configuration exists
|
|
assert:
|
|
that:
|
|
- haproxy_config.stat.exists
|
|
fail_msg: "HAProxy configuration does not exist"
|
|
success_msg: "HAProxy configuration exists"
|
|
|
|
- name: Verify monitoring
|
|
hosts: monitoring
|
|
become: true
|
|
tasks:
|
|
- name: Check monitoring tools
|
|
command: which htop
|
|
register: htop_check
|
|
changed_when: false
|
|
|
|
- name: Verify monitoring tools are installed
|
|
assert:
|
|
that:
|
|
- htop_check.rc == 0
|
|
fail_msg: "Monitoring tools are not installed"
|
|
success_msg: "Monitoring tools are installed"
|
|
|
|
- name: Check monitoring script
|
|
stat:
|
|
path: /usr/local/bin/system-info.sh
|
|
register: monitor_script
|
|
|
|
- name: Verify monitoring script exists
|
|
assert:
|
|
that:
|
|
- monitor_script.stat.exists
|
|
fail_msg: "Monitoring script does not exist"
|
|
success_msg: "Monitoring script exists"
|
|
|
|
- name: Test monitoring script
|
|
command: /usr/local/bin/system-info.sh
|
|
register: monitor_output
|
|
changed_when: false
|
|
|
|
- name: Verify monitoring script works
|
|
assert:
|
|
that:
|
|
- monitor_output.rc == 0
|
|
- monitor_output.stdout | length > 0
|
|
fail_msg: "Monitoring script failed"
|
|
success_msg: "Monitoring script works correctly"
|
|
|
|
- name: Network connectivity tests
|
|
hosts: all
|
|
tasks:
|
|
- name: Test connectivity to web servers
|
|
wait_for:
|
|
host: "{{ item }}"
|
|
port: 80
|
|
timeout: 10
|
|
loop:
|
|
- web1
|
|
- web2
|
|
when: "'web' not in group_names"
|
|
ignore_errors: true
|
|
|
|
- name: Test connectivity to app servers
|
|
wait_for:
|
|
host: "{{ item }}"
|
|
port: 8080
|
|
timeout: 10
|
|
loop:
|
|
- app1
|
|
when: "'app' not in group_names"
|
|
ignore_errors: true
|
|
|
|
- name: Test connectivity to cache servers
|
|
wait_for:
|
|
host: "{{ item }}"
|
|
port: 6379
|
|
timeout: 10
|
|
loop:
|
|
- cache1
|
|
when: "'cache' not in group_names"
|
|
ignore_errors: true
|
|
|
|
- name: Test connectivity to load balancer
|
|
wait_for:
|
|
host: lb1
|
|
port: 80
|
|
timeout: 10
|
|
when: "'loadbalancer' not in group_names"
|
|
ignore_errors: true
|
|
|
|
- name: Final verification summary
|
|
hosts: localhost
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Display verification summary
|
|
debug:
|
|
msg: |
|
|
========================================
|
|
Verification Summary
|
|
========================================
|
|
- Web servers: {{ 'OK' if web_servers_ok is defined else 'SKIPPED' }}
|
|
- App servers: {{ 'OK' if app_servers_ok is defined else 'SKIPPED' }}
|
|
- Database servers: {{ 'OK' if database_servers_ok is defined else 'SKIPPED' }}
|
|
- Cache servers: {{ 'OK' if cache_servers_ok is defined else 'SKIPPED' }}
|
|
- Load balancer: {{ 'OK' if loadbalancer_ok is defined else 'SKIPPED' }}
|
|
- Monitoring: {{ 'OK' if monitoring_ok is defined else 'SKIPPED' }}
|
|
======================================== |