feat(ansible): Add nginx role tasks
This commit is contained in:
66
ansible/webserver-automation/roles/nginx/tasks/main.yml
Normal file
66
ansible/webserver-automation/roles/nginx/tasks/main.yml
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
---
|
||||||
|
# Nginx role - Web server installation and configuration
|
||||||
|
|
||||||
|
- name: Install Nginx
|
||||||
|
apt:
|
||||||
|
name: nginx
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
||||||
|
tags: ['install']
|
||||||
|
|
||||||
|
- name: Ensure Nginx is started and enabled
|
||||||
|
service:
|
||||||
|
name: nginx
|
||||||
|
state: started
|
||||||
|
enabled: true
|
||||||
|
tags: ['service']
|
||||||
|
|
||||||
|
- name: Create web root directory
|
||||||
|
file:
|
||||||
|
path: "{{ app_dir }}"
|
||||||
|
state: directory
|
||||||
|
owner: "{{ app_user }}"
|
||||||
|
group: "{{ app_group }}"
|
||||||
|
mode: '0755'
|
||||||
|
tags: ['setup']
|
||||||
|
|
||||||
|
- name: Remove default Nginx site
|
||||||
|
file:
|
||||||
|
path: /etc/nginx/sites-enabled/default
|
||||||
|
state: absent
|
||||||
|
notify: reload nginx
|
||||||
|
tags: ['config']
|
||||||
|
|
||||||
|
- name: Create Nginx site configuration
|
||||||
|
template:
|
||||||
|
src: nginx-site.conf.j2
|
||||||
|
dest: "/etc/nginx/sites-available/{{ app_name }}"
|
||||||
|
mode: '0644'
|
||||||
|
notify: reload nginx
|
||||||
|
tags: ['config']
|
||||||
|
|
||||||
|
- name: Enable Nginx site
|
||||||
|
file:
|
||||||
|
src: "/etc/nginx/sites-available/{{ app_name }}"
|
||||||
|
dest: "/etc/nginx/sites-enabled/{{ app_name }}"
|
||||||
|
state: link
|
||||||
|
notify: reload nginx
|
||||||
|
tags: ['config']
|
||||||
|
|
||||||
|
- name: Create sample index.html
|
||||||
|
template:
|
||||||
|
src: index.html.j2
|
||||||
|
dest: "{{ app_dir }}/index.html"
|
||||||
|
owner: "{{ app_user }}"
|
||||||
|
group: "{{ app_group }}"
|
||||||
|
mode: '0644'
|
||||||
|
tags: ['content']
|
||||||
|
|
||||||
|
- name: Test Nginx configuration
|
||||||
|
command: nginx -t
|
||||||
|
changed_when: false
|
||||||
|
tags: ['verify']
|
||||||
|
|
||||||
|
- name: Display status
|
||||||
|
debug:
|
||||||
|
msg: "✅ Nginx configured - Port {{ nginx_port }}"
|
||||||
Reference in New Issue
Block a user