Обновление проекта

This commit is contained in:
Сергей Антропов
2025-10-30 01:10:35 +03:00
parent 2ce450215b
commit 981ede5c94
15 changed files with 440 additions and 1064 deletions

View File

@@ -12,195 +12,6 @@ ROLES=$(find roles/ -name 'main.yml' -path '*/tasks/*' | sed 's|roles/||; s|/tas
echo "📋 Найденные роли: $ROLES"
# Обновляем molecule/default/run.yml (только если файл не существует)
if [ ! -f "molecule/default/run.yml" ]; then
echo "📝 Создание molecule/default/run.yml..."
cat > molecule/default/run.yml << 'EOF'
---
# Универсальный playbook для тестирования Ansible ролей
# Автор: Сергей Антропов
# Сайт: https://devops.org.ru
#
# Этот файл отвечает за:
# 1. Обновление пакетов в контейнерах при запуске тестов
# 2. Установку common tools для корректной работы тестов
# 3. Подготовку окружения для тестирования ролей
# 4. Импорт roles/deploy.yml для запуска ролей
- name: Подготовка окружения для тестирования
hosts: all
become: true
tasks:
# Обновление кеша пакетов для Debian/Ubuntu
- name: Update package cache (Debian/Ubuntu)
apt:
update_cache: true
cache_valid_time: 3600
when: ansible_os_family == 'Debian'
changed_when: false
tags:
- setup
- update
# Обновление кеша пакетов для RHEL/CentOS/AlmaLinux/Rocky
- name: Update package cache (RHEL/CentOS/AlmaLinux/Rocky)
yum:
update_cache: true
when: ansible_os_family == 'RedHat'
changed_when: false
tags:
- setup
- update
# Обновление кеша пакетов для Alt Linux
- name: Update package cache (Alt Linux)
apt:
update_cache: true
when: ansible_distribution == 'Alt'
changed_when: false
tags:
- setup
- update
# Установка common tools для всех ОС
- name: Install common tools (Debian/Ubuntu)
apt:
name:
- curl
- jq
- ca-certificates
- iproute2
- iputils-ping
- procps
- net-tools
- sudo
- vim
- wget
- unzip
- git
state: present
update_cache: false
when: ansible_os_family == 'Debian'
tags:
- setup
- tools
- name: Install common tools (RHEL/CentOS/AlmaLinux/Rocky)
yum:
name:
- curl
- jq
- ca-certificates
- iproute
- iputils
- procps-ng
- net-tools
- sudo
- vim
- wget
- unzip
- git
state: present
when: ansible_os_family == 'RedHat'
tags:
- setup
- tools
- name: Install common tools (Alt Linux)
apt:
name:
- curl
- jq
- ca-certificates
- iproute2
- iputils
- procps
- net-tools
- sudo
- vim
- wget
- unzip
- git
state: present
when: ansible_distribution == 'Alt'
tags:
- setup
- tools
# Установка Python для Ansible (если не установлен)
- name: Install Python (Debian/Ubuntu)
apt:
name:
- python3
- python3-pip
- python3-venv
state: present
when: ansible_os_family == 'Debian'
tags:
- setup
- python
- name: Install Python (RHEL/CentOS/AlmaLinux/Rocky)
yum:
name:
- python3
- python3-pip
state: present
when: ansible_os_family == 'RedHat'
tags:
- setup
- python
- name: Install Python (Alt Linux)
apt:
name:
- python3
- python3-pip
state: present
when: ansible_distribution == 'Alt'
tags:
- setup
- python
# Создание пользователя для тестирования
- name: Create test user
user:
name: testuser
shell: /bin/bash
create_home: yes
state: present
tags:
- setup
- user
# Настройка sudo для тестового пользователя
- name: Configure sudo for test user
lineinfile:
path: /etc/sudoers
line: "testuser ALL=(ALL) NOPASSWD:ALL"
state: present
validate: 'visudo -cf %s'
tags:
- setup
- sudo
# Создание директории для тестов
- name: Create test directory
file:
path: /tmp/ansible-test
state: directory
mode: '0755'
owner: testuser
group: testuser
tags:
- setup
- directory
- import_playbook: ../../roles/deploy.yml
EOF
else
echo "📝 Файл molecule/default/run.yml уже существует, пропускаем создание"
fi
# Обновляем roles/deploy.yml
echo "📝 Обновление roles/deploy.yml..."
@@ -210,13 +21,17 @@ cat > roles/deploy.yml << EOF
# Автор: Сергей Антропов
# Сайт: https://devops.org.ru
- name: Развертывание всех ролей
hosts: all
roles:
EOF
# Добавляем каждую роль как отдельный playbook блок
for role in $ROLES; do
echo " - $role" >> roles/deploy.yml
cat >> roles/deploy.yml << EOF
- name: Установка роли $role
hosts: all
become: true
roles:
- $role
EOF
done
echo "✅ Playbook'и обновлены"