From ea874f1ca5ab74568a73f42143650fcdc8bb267e Mon Sep 17 00:00:00 2001 From: ogrechko Date: Fri, 22 May 2026 15:28:18 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20ansible/npm-setup.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ansible/npm-setup.yml | 69 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/ansible/npm-setup.yml b/ansible/npm-setup.yml index bc4d0a7..be145e6 100644 --- a/ansible/npm-setup.yml +++ b/ansible/npm-setup.yml @@ -1,15 +1,43 @@ --- -# 1. Динамическое добавление машины в инвентарь -- name: Add dynamically provisioned host +# 1. Проверка наличия переменных и динамическое добавление хоста +- name: Validate input and add host dynamically hosts: localhost gather_facts: no tasks: - - name: Add new VM IP to inventory + - name: Check if vm_ip is provided + fail: + msg: | + ======================================== + ERROR: VM IP address is required! + + Please provide vm_ip variable when running this playbook. + + Example in Semaphore: + - Add vm_ip in Extra Variables + ======================================== + when: vm_ip is not defined or vm_ip == "" + + - name: Check if ansible_user is provided + fail: + msg: "ERROR: ansible_user is required! Please provide SSH username." + when: ansible_user is not defined or ansible_user == "" + + - name: Display target information + debug: + msg: | + ======================================== + Target Configuration: + - IP Address: {{ vm_ip }} + - SSH User: {{ ansible_user }} + ======================================== + + - name: Add new VM to inventory add_host: name: "{{ vm_ip }}" groups: npm_servers - ansible_user: ogrechko # Замените на логин вашего шаблона + ansible_user: "{{ ansible_user }}" ansible_ssh_common_args: '-o StrictHostKeyChecking=no' + ansible_become: yes # 2. Основная настройка NPM - name: Setup Minimal Linux with Docker and Nginx Proxy Manager @@ -17,12 +45,20 @@ become: yes gather_facts: yes tasks: + - name: Display facts about target + debug: + msg: "Setting up Docker and NPM on {{ ansible_hostname }} ({{ ansible_default_ipv4.address }})" + - name: Update apt cache and install prerequisites apt: name: ['apt-transport-https', 'ca-certificates', 'curl', 'gnupg', 'lsb-release'] state: present update_cache: yes + - name: Check system architecture + debug: + msg: "System architecture: {{ ansible_architecture }}" + - name: Add Docker GPG apt Key apt_key: url: https://download.docker.com/linux/debian/gpg @@ -45,6 +81,13 @@ state: started enabled: yes + - name: Add user to docker group + user: + name: "{{ ansible_user }}" + groups: docker + append: yes + when: ansible_user != 'root' + - name: Create directory for Nginx Proxy Manager file: path: /opt/npm @@ -71,4 +114,20 @@ - name: Run Nginx Proxy Manager via Docker Compose community.docker.docker_compose_v2: project_src: /opt/npm - state: present \ No newline at end of file + state: present + + - name: Display access information + debug: + msg: | + ======================================== + ✅ Nginx Proxy Manager is ready! + + Access URLs: + - Admin Panel: http://{{ vm_ip }}:81 + - HTTP Proxy: http://{{ vm_ip }} + - HTTPS Proxy: https://{{ vm_ip }} + + Default Admin Credentials (change on first login): + - Email: admin@example.com + - Password: changeme + ======================================== \ No newline at end of file