feat: enhance Ansible playbook with swap file management
- Update inventory to use root user with SSH options for security - Add tasks for creating, configuring, and enabling a swap file - Set swappiness parameter temporarily and permanently - Ensure swap file is added to /etc/fstab for automatic mounting - Include checks and debug information for swap status
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
[new_server]
|
[new_server]
|
||||||
127.0.0.1 ansible_user=deploy
|
127.0.0.1 ansible_user=root ansible_ssh_common_args='-o StrictHostKeyChecking=no'
|
||||||
|
|
||||||
[all:vars]
|
[all:vars]
|
||||||
ansible_python_interpreter=/usr/bin/python3
|
ansible_python_interpreter=/usr/bin/python3
|
||||||
@@ -29,10 +29,6 @@
|
|||||||
run_once: true
|
run_once: true
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
|
|
||||||
- name: Переключиться на root для начальной настройки
|
|
||||||
set_fact:
|
|
||||||
ansible_user: root
|
|
||||||
|
|
||||||
- name: Обновить кэш пакетов
|
- name: Обновить кэш пакетов
|
||||||
apt:
|
apt:
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
@@ -58,6 +54,60 @@
|
|||||||
- prometheus-node-exporter
|
- prometheus-node-exporter
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
|
- name: Проверить существование swap-файла
|
||||||
|
stat:
|
||||||
|
path: /swapfile
|
||||||
|
register: swap_file_stat
|
||||||
|
|
||||||
|
- name: Создать swap-файл (2GB)
|
||||||
|
command: fallocate -l 2G /swapfile
|
||||||
|
when: not swap_file_stat.stat.exists
|
||||||
|
|
||||||
|
- name: Установить правильные права на swap-файл
|
||||||
|
file:
|
||||||
|
path: /swapfile
|
||||||
|
mode: '0600'
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
|
||||||
|
- name: Настроить swap-файл
|
||||||
|
command: mkswap /swapfile
|
||||||
|
when: not swap_file_stat.stat.exists
|
||||||
|
|
||||||
|
- name: Включить swap-файл
|
||||||
|
command: swapon /swapfile
|
||||||
|
when: not swap_file_stat.stat.exists
|
||||||
|
|
||||||
|
- name: Настроить swappiness = 10 (временно)
|
||||||
|
sysctl:
|
||||||
|
name: vm.swappiness
|
||||||
|
value: '10'
|
||||||
|
state: present
|
||||||
|
reload: yes
|
||||||
|
|
||||||
|
- name: Настроить swappiness = 10 (постоянно)
|
||||||
|
lineinfile:
|
||||||
|
path: /etc/sysctl.conf
|
||||||
|
regexp: '^vm\.swappiness\s*='
|
||||||
|
line: 'vm.swappiness = 10'
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Добавить swap-файл в /etc/fstab для автоматического монтирования
|
||||||
|
lineinfile:
|
||||||
|
path: /etc/fstab
|
||||||
|
line: '/swapfile none swap sw 0 0'
|
||||||
|
state: present
|
||||||
|
create: yes
|
||||||
|
|
||||||
|
- name: Проверить статус swap
|
||||||
|
command: swapon --show
|
||||||
|
register: swap_status
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Показать информацию о swap
|
||||||
|
debug:
|
||||||
|
var: swap_status.stdout_lines
|
||||||
|
|
||||||
- name: Включить и запустить prometheus-node-exporter
|
- name: Включить и запустить prometheus-node-exporter
|
||||||
systemd:
|
systemd:
|
||||||
name: prometheus-node-exporter
|
name: prometheus-node-exporter
|
||||||
@@ -129,9 +179,6 @@
|
|||||||
register: user_exists
|
register: user_exists
|
||||||
failed_when: false
|
failed_when: false
|
||||||
|
|
||||||
- name: Переключиться на пользователя deploy
|
|
||||||
meta: reset_connection
|
|
||||||
|
|
||||||
- name: Создать группу deploy с GID 1001
|
- name: Создать группу deploy с GID 1001
|
||||||
group:
|
group:
|
||||||
name: "{{ deploy_user }}"
|
name: "{{ deploy_user }}"
|
||||||
@@ -212,6 +259,9 @@
|
|||||||
group: "{{ deploy_user }}"
|
group: "{{ deploy_user }}"
|
||||||
mode: '0600'
|
mode: '0600'
|
||||||
|
|
||||||
|
- name: Переключиться на пользователя deploy
|
||||||
|
meta: reset_connection
|
||||||
|
|
||||||
- name: Клонировать основной репозиторий prod
|
- name: Клонировать основной репозиторий prod
|
||||||
git:
|
git:
|
||||||
repo: git@github.com:KerradKerridi/prod.git
|
repo: git@github.com:KerradKerridi/prod.git
|
||||||
@@ -239,6 +289,15 @@
|
|||||||
become: yes
|
become: yes
|
||||||
become_user: "{{ deploy_user }}"
|
become_user: "{{ deploy_user }}"
|
||||||
|
|
||||||
|
- name: Установить правильные права на дашборд Node Exporter Full
|
||||||
|
file:
|
||||||
|
path: "{{ project_root }}/infra/grafana/provisioning/dashboards/node-exporter-full-dashboard.json"
|
||||||
|
owner: "{{ deploy_user }}"
|
||||||
|
group: "{{ deploy_user }}"
|
||||||
|
mode: '0644'
|
||||||
|
become: yes
|
||||||
|
become_user: "{{ deploy_user }}"
|
||||||
|
|
||||||
- name: Скопировать SSH ключ на старый сервер для копирования файлов
|
- name: Скопировать SSH ключ на старый сервер для копирования файлов
|
||||||
authorized_key:
|
authorized_key:
|
||||||
user: root
|
user: root
|
||||||
@@ -416,22 +475,13 @@
|
|||||||
recurse: yes
|
recurse: yes
|
||||||
become: yes
|
become: yes
|
||||||
|
|
||||||
- name: Убедиться, что дашборд Node Exporter Full скопирован
|
|
||||||
copy:
|
|
||||||
src: "{{ project_root }}/infra/grafana/provisioning/dashboards/node-exporter-full-dashboard.json"
|
|
||||||
dest: "{{ project_root }}/infra/grafana/provisioning/dashboards/node-exporter-full-dashboard.json"
|
|
||||||
owner: "{{ deploy_user }}"
|
|
||||||
group: "{{ deploy_user }}"
|
|
||||||
mode: '0644'
|
|
||||||
become: yes
|
|
||||||
become_user: "{{ deploy_user }}"
|
|
||||||
|
|
||||||
- name: Запустить ботов через make up
|
- name: Запустить ботов через make up
|
||||||
command: make up
|
command: make up
|
||||||
args:
|
args:
|
||||||
chdir: "{{ project_root }}"
|
chdir: "{{ project_root }}"
|
||||||
become: yes
|
become: yes
|
||||||
become_user: "{{ deploy_user }}"
|
become_user: "{{ deploy_user }}"
|
||||||
|
tags: ["start_bots"]
|
||||||
|
|
||||||
# --- НОВОЕ: Проверка портов ---
|
# --- НОВОЕ: Проверка портов ---
|
||||||
- name: Пауза на 30 секунд — дать контейнерам запуститься
|
- name: Пауза на 30 секунд — дать контейнерам запуститься
|
||||||
|
|||||||
Reference in New Issue
Block a user