Обновить ansible/npm-setup.yml
This commit is contained in:
+64
-5
@@ -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
|
||||
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
|
||||
========================================
|
||||
Reference in New Issue
Block a user