diff --git a/infra/ansible/inventory.ini b/infra/ansible/inventory.ini index 50f4747..b1c7f96 100644 --- a/infra/ansible/inventory.ini +++ b/infra/ansible/inventory.ini @@ -1,5 +1,5 @@ [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] ansible_python_interpreter=/usr/bin/python3 \ No newline at end of file diff --git a/infra/ansible/playbook.yml b/infra/ansible/playbook.yml index 6a026bb..01f1b0f 100644 --- a/infra/ansible/playbook.yml +++ b/infra/ansible/playbook.yml @@ -29,10 +29,6 @@ run_once: true ignore_errors: yes - - name: Переключиться на root для начальной настройки - set_fact: - ansible_user: root - - name: Обновить кэш пакетов apt: update_cache: yes @@ -58,6 +54,60 @@ - prometheus-node-exporter 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 systemd: name: prometheus-node-exporter @@ -129,9 +179,6 @@ register: user_exists failed_when: false - - name: Переключиться на пользователя deploy - meta: reset_connection - - name: Создать группу deploy с GID 1001 group: name: "{{ deploy_user }}" @@ -212,6 +259,9 @@ group: "{{ deploy_user }}" mode: '0600' + - name: Переключиться на пользователя deploy + meta: reset_connection + - name: Клонировать основной репозиторий prod git: repo: git@github.com:KerradKerridi/prod.git @@ -239,6 +289,15 @@ become: yes 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 ключ на старый сервер для копирования файлов authorized_key: user: root @@ -416,22 +475,13 @@ recurse: 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 command: make up args: chdir: "{{ project_root }}" become: yes become_user: "{{ deploy_user }}" + tags: ["start_bots"] # --- НОВОЕ: Проверка портов --- - name: Пауза на 30 секунд — дать контейнерам запуститься