This commit is contained in:
reqwizz 2024-11-11 23:16:26 +03:00
parent ac4bad6936
commit c273781043
13 changed files with 49 additions and 68 deletions

View File

@ -1,4 +1,4 @@
[defaults] [defaults]
inventory = inventory.yml inventory = inventory.yml
roles_path = ./ansible/roles roles_path = ./roles
host_key_checking = False host_key_checking = False

View File

@ -1,3 +1,4 @@
- hosts: all - hosts: all
become: true
roles: roles:
- site_setup - site_setup

View File

@ -1,4 +1,3 @@
---
- name: Start and enable firewalld - name: Start and enable firewalld
service: service:
name: firewalld name: firewalld

View File

@ -0,0 +1,11 @@
- name: Configure Nginx as HTTPS proxy
template:
src: proxy.conf.j2
dest: /etc/nginx/conf.d/proxy.conf
tags: proxy
- name: Restart Nginx
service:
name: nginx
state: restarted
tags: proxy

View File

@ -1,25 +1,24 @@
---
- name: Create site directories - name: Create site directories
file: file:
path: "/var/www/html/{{ site_name }}" path: "/var/www/{{ site_name }}"
state: directory state: directory
mode: '0755' mode: '0755'
tags: configure tags: configure_site
- name: Deploy site content - name: Deploy site content
template: template:
src: site_index.html.j2 src: site_index.html.j2
dest: "/var/www/html/{{ site_name }}/index.html" dest: "/var/www/{{ site_name }}/index.html"
tags: configure tags: configure_site
- name: Configure Nginx for {{ site_name }} - name: Configure Nginx for {{ site_name }}
template: template:
src: nginx_site.conf.j2 src: nginx_site.conf.j2
dest: "/etc/nginx/conf.d/{{ site_name }}.conf" dest: "/etc/nginx/conf.d/{{ site_name }}.conf"
tags: configure tags: configure_site
- name: Restart Nginx - name: Restart Nginx
service: service:
name: nginx name: nginx
state: restarted state: restarted
tags: configure tags: configure_site

View File

@ -1,24 +1,26 @@
---
- name: Ensure SSL directory exists - name: Ensure SSL directory exists
file: file:
path: /etc/nginx/ssl path: /etc/nginx/ssl
state: directory state: directory
mode: '0755' mode: '0700'
tags: ssl
- name: Generate private key
openssl_privatekey:
path: /etc/nginx/ssl/{{ proxy_name }}.key
size: 2048
type: RSA
mode: '0600'
owner: root
group: root
tags: ssl tags: ssl
- name: Generate self-signed SSL certificate - name: Generate self-signed SSL certificate
openssl_certificate: openssl_certificate:
path: /etc/nginx/ssl/{{ proxy_name }}.crt path: /etc/nginx/ssl/{{ proxy_name }}.crt
privatekey_path: /etc/nginx/ssl/{{ proxy_name }}.key privatekey_path: /etc/nginx/ssl/{{ proxy_name }}.key
common_name: "{{ proxy_name }}"
state: present
selfsigned: yes
owner: root owner: root
group: root group: root
mode: '0644' mode: '0600'
subject: provider: selfsigned
- organizationName: "Example Company"
- organizationalUnitName: "IT"
- localityName: "City"
- countryName: "US"
tags: ssl tags: ssl

View File

@ -1,4 +1,3 @@
---
- name: Install Nginx - name: Install Nginx
zypper: zypper:
name: nginx name: nginx

View File

@ -1,12 +1,14 @@
---
- import_tasks: install.yml - import_tasks: install.yml
tags: install tags: install
- import_tasks: configure.yml - import_tasks: configure_site.yml
tags: configure tags: configure_site
- import_tasks: proxy.yml - import_tasks: configure_firewall.yml
tags: proxy
- import_tasks: firewall.yml
tags: firewall tags: firewall
- import_tasks: generate_ssl.yml
tags: ssl
- import_tasks: configure_proxy.yml
tags: proxy

View File

@ -1,26 +0,0 @@
---
- name: Configure Nginx load balancer with SSL
template:
src: nginx_proxy_ssl.conf.j2
dest: "/etc/nginx/conf.d/proxy.conf"
tags: proxy
- name: Ensure SSL directory exists
file:
path: /etc/nginx/ssl
state: directory
mode: '0755'
tags: proxy
- name: Copy Diffie-Hellman parameters
copy:
src: dhparam.pem
dest: /etc/nginx/ssl/dhparam.pem
mode: '0600'
tags: proxy
- name: Restart Nginx after configuration
service:
name: nginx
state: restarted
tags: proxy

View File

@ -3,7 +3,7 @@ server {
server_name {{ site_name }}; server_name {{ site_name }};
location / { location / {
root /var/www/html/{{ site_name }}; root /var/www/{{ site_name }};
index index.html; index index.html;
} }
} }

View File

@ -15,11 +15,6 @@ server {
ssl_certificate /etc/nginx/ssl/{{ proxy_name }}.crt; ssl_certificate /etc/nginx/ssl/{{ proxy_name }}.crt;
ssl_certificate_key /etc/nginx/ssl/{{ proxy_name }}.key; ssl_certificate_key /etc/nginx/ssl/{{ proxy_name }}.key;
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384";
location / { location / {
proxy_pass http://backend_servers; proxy_pass http://backend_servers;

View File

@ -1,4 +1,3 @@
---
site_name: "example_site" site_name: "example_site"
proxy_name: "proxy_server" proxy_name: "proxy_server"
backend_ip_1: "192.168.0.61" backend_ip_1: "192.168.0.61"