Обновить ansible/npm-setup.yml
This commit is contained in:
+48
-47
@@ -1,27 +1,31 @@
|
|||||||
---
|
---
|
||||||
# 1. Проверка наличия переменных и динамическое добавление хоста
|
|
||||||
- name: Validate input and add host dynamically
|
- name: Validate input and add host dynamically
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
|
vars:
|
||||||
|
# Пытаемся определить метод аутентификации
|
||||||
|
auth_method: "{{ 'key' if ssh_key_path is defined else 'password' }}"
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Check if vm_ip is provided
|
- name: Check if vm_ip is provided
|
||||||
fail:
|
fail:
|
||||||
msg: |
|
msg: "ERROR: VM IP address is required!"
|
||||||
========================================
|
|
||||||
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 == ""
|
when: vm_ip is not defined or vm_ip == ""
|
||||||
|
|
||||||
- name: Check if ansible_user is provided
|
- name: Check if ansible_user is provided
|
||||||
fail:
|
fail:
|
||||||
msg: "ERROR: ansible_user is required! Please provide SSH username."
|
msg: "ERROR: ansible_user is required!"
|
||||||
when: ansible_user is not defined or ansible_user == ""
|
when: ansible_user is not defined or ansible_user == ""
|
||||||
|
|
||||||
|
- name: Check authentication method
|
||||||
|
fail:
|
||||||
|
msg: |
|
||||||
|
ERROR: Neither password nor SSH key provided!
|
||||||
|
Please provide either:
|
||||||
|
- ansible_password variable for password auth
|
||||||
|
- ssh_key_path variable for key auth
|
||||||
|
when: ansible_password is not defined and ssh_key_path is not defined
|
||||||
|
|
||||||
- name: Display target information
|
- name: Display target information
|
||||||
debug:
|
debug:
|
||||||
msg: |
|
msg: |
|
||||||
@@ -29,72 +33,75 @@
|
|||||||
Target Configuration:
|
Target Configuration:
|
||||||
- IP Address: {{ vm_ip }}
|
- IP Address: {{ vm_ip }}
|
||||||
- SSH User: {{ ansible_user }}
|
- SSH User: {{ ansible_user }}
|
||||||
|
- Auth Method: {{ 'SSH Key' if ssh_key_path is defined else 'Password' }}
|
||||||
========================================
|
========================================
|
||||||
|
|
||||||
- name: Add new VM to inventory
|
- name: Add host with password authentication
|
||||||
add_host:
|
add_host:
|
||||||
name: "{{ vm_ip }}"
|
name: "{{ vm_ip }}"
|
||||||
groups: npm_servers
|
groups: npm_servers
|
||||||
ansible_user: "{{ ansible_user }}"
|
ansible_user: "{{ ansible_user }}"
|
||||||
|
ansible_ssh_pass: "{{ ansible_password }}"
|
||||||
|
ansible_become_pass: "{{ ansible_password }}"
|
||||||
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
|
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
|
||||||
ansible_become: yes
|
when: ansible_password is defined
|
||||||
|
|
||||||
|
- name: Add host with key authentication
|
||||||
|
add_host:
|
||||||
|
name: "{{ vm_ip }}"
|
||||||
|
groups: npm_servers
|
||||||
|
ansible_user: "{{ ansible_user }}"
|
||||||
|
ansible_ssh_private_key_file: "{{ ssh_key_path }}"
|
||||||
|
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
|
||||||
|
when: ssh_key_path is defined
|
||||||
|
|
||||||
# 2. Основная настройка NPM
|
|
||||||
- name: Setup Minimal Linux with Docker and Nginx Proxy Manager
|
- name: Setup Minimal Linux with Docker and Nginx Proxy Manager
|
||||||
hosts: npm_servers
|
hosts: npm_servers
|
||||||
become: yes
|
become: yes
|
||||||
gather_facts: yes
|
gather_facts: yes
|
||||||
tasks:
|
tasks:
|
||||||
- name: Display facts about target
|
# ... остальные задачи как выше ...
|
||||||
debug:
|
- name: Test connection
|
||||||
msg: "Setting up Docker and NPM on {{ ansible_hostname }} ({{ ansible_default_ipv4.address }})"
|
ping:
|
||||||
|
|
||||||
- name: Update apt cache and install prerequisites
|
- name: Update apt cache
|
||||||
|
apt:
|
||||||
|
update_cache: yes
|
||||||
|
|
||||||
|
- name: Install Docker prerequisites
|
||||||
apt:
|
apt:
|
||||||
name: ['apt-transport-https', 'ca-certificates', 'curl', 'gnupg', 'lsb-release']
|
name: ['apt-transport-https', 'ca-certificates', 'curl', 'gnupg', 'lsb-release']
|
||||||
state: present
|
state: present
|
||||||
update_cache: yes
|
|
||||||
|
|
||||||
- name: Check system architecture
|
- name: Add Docker GPG key
|
||||||
debug:
|
|
||||||
msg: "System architecture: {{ ansible_architecture }}"
|
|
||||||
|
|
||||||
- name: Add Docker GPG apt Key
|
|
||||||
apt_key:
|
apt_key:
|
||||||
url: https://download.docker.com/linux/debian/gpg
|
url: https://download.docker.com/linux/debian/gpg
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Add Docker Repository
|
- name: Add Docker repository
|
||||||
apt_repository:
|
apt_repository:
|
||||||
repo: "deb [arch=amd64] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable"
|
repo: "deb [arch=amd64] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Install Docker and Docker Compose Plugin
|
- name: Install Docker
|
||||||
apt:
|
apt:
|
||||||
name: ['docker-ce', 'docker-ce-cli', 'containerd.io', 'docker-compose-plugin']
|
name: ['docker-ce', 'docker-ce-cli', 'containerd.io', 'docker-compose-plugin']
|
||||||
state: present
|
state: present
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
|
|
||||||
- name: Ensure Docker service is running and enabled
|
- name: Start Docker
|
||||||
systemd:
|
systemd:
|
||||||
name: docker
|
name: docker
|
||||||
state: started
|
state: started
|
||||||
enabled: yes
|
enabled: yes
|
||||||
|
|
||||||
- name: Add user to docker group
|
- name: Setup Nginx Proxy Manager
|
||||||
user:
|
|
||||||
name: "{{ ansible_user }}"
|
|
||||||
groups: docker
|
|
||||||
append: yes
|
|
||||||
when: ansible_user != 'root'
|
|
||||||
|
|
||||||
- name: Create directory for Nginx Proxy Manager
|
|
||||||
file:
|
file:
|
||||||
path: /opt/npm
|
path: /opt/npm
|
||||||
state: directory
|
state: directory
|
||||||
mode: '0755'
|
mode: '0755'
|
||||||
|
|
||||||
- name: Create docker-compose.yml for NPM
|
- name: Deploy NPM compose file
|
||||||
copy:
|
copy:
|
||||||
dest: /opt/npm/docker-compose.yml
|
dest: /opt/npm/docker-compose.yml
|
||||||
content: |
|
content: |
|
||||||
@@ -111,23 +118,17 @@
|
|||||||
- ./data:/data
|
- ./data:/data
|
||||||
- ./letsencrypt:/etc/letsencrypt
|
- ./letsencrypt:/etc/letsencrypt
|
||||||
|
|
||||||
- name: Run Nginx Proxy Manager via Docker Compose
|
- name: Start NPM
|
||||||
community.docker.docker_compose_v2:
|
community.docker.docker_compose_v2:
|
||||||
project_src: /opt/npm
|
project_src: /opt/npm
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Display access information
|
- name: Success message
|
||||||
debug:
|
debug:
|
||||||
msg: |
|
msg: |
|
||||||
========================================
|
========================================
|
||||||
✅ Nginx Proxy Manager is ready!
|
✅ Docker and Nginx Proxy Manager installed!
|
||||||
|
|
||||||
Access URLs:
|
Access NPM Admin: http://{{ vm_ip }}:81
|
||||||
- Admin Panel: http://{{ vm_ip }}:81
|
Default login: admin@example.com / changeme
|
||||||
- HTTP Proxy: http://{{ vm_ip }}
|
|
||||||
- HTTPS Proxy: https://{{ vm_ip }}
|
|
||||||
|
|
||||||
Default Admin Credentials (change on first login):
|
|
||||||
- Email: admin@example.com
|
|
||||||
- Password: changeme
|
|
||||||
========================================
|
========================================
|
||||||
Reference in New Issue
Block a user