57 lines
1.4 KiB
YAML
57 lines
1.4 KiB
YAML
---
|
|
# Nginx installation and configuration tasks
|
|
- name: Install Nginx
|
|
apt:
|
|
name: nginx
|
|
state: present
|
|
update_cache: yes
|
|
|
|
- name: Start and enable Nginx service
|
|
systemd:
|
|
name: nginx
|
|
state: started
|
|
enabled: yes
|
|
|
|
- name: Remove default Nginx site
|
|
file:
|
|
path: /etc/nginx/sites-enabled/default
|
|
state: absent
|
|
|
|
- name: Create SSL directory
|
|
file:
|
|
path: "{{ nginx_ssl_path }}"
|
|
state: directory
|
|
mode: '0755'
|
|
|
|
- name: Create Nginx configuration for {{ trillium_domain }}
|
|
template:
|
|
src: nginx-site.conf.j2
|
|
dest: "{{ nginx_config_path }}/{{ trillium_domain }}"
|
|
|
|
- name: Verify Nginx configuration file exists
|
|
stat:
|
|
path: "{{ nginx_config_path }}/{{ trillium_domain }}"
|
|
register: nginx_config_stat
|
|
|
|
- name: Enable Nginx site
|
|
file:
|
|
src: "{{ nginx_config_path }}/{{ trillium_domain }}"
|
|
dest: "/etc/nginx/sites-enabled/{{ trillium_domain }}"
|
|
state: link
|
|
when: nginx_config_stat.stat.exists
|
|
|
|
- name: Test Nginx configuration
|
|
command: nginx -t
|
|
register: nginx_test
|
|
changed_when: false
|
|
|
|
- name: Display Nginx test result
|
|
debug:
|
|
msg: "{{ nginx_test.stdout }}"
|
|
|
|
- name: Restart Nginx if configuration changed
|
|
systemd:
|
|
name: nginx
|
|
state: restarted
|
|
when: nginx_test.stdout is defined
|