nginx/tasks/install.yml

75 lines
1.7 KiB
YAML
Raw Normal View History

2021-09-18 19:37:57 +00:00
---
- name: Install Nginx
apt:
name: nginx
- name: Create directories for Nginx configuration
notify: nginx | Restart Nginx
file:
state: directory
path: '{{ item }}'
mode: 'u=rwx,go=rx'
owner: root
group: root
with_items:
- '{{ nginx__conf_dir }}'
- '{{ nginx__confd_dir }}'
- '{{ nginx__available_dir }}'
- '{{ nginx__enabled_dir }}'
- '{{ nginx__snippets_dir }}'
2023-03-30 06:20:55 +00:00
- name: Install Nginx config
2021-09-18 19:37:57 +00:00
notify: nginx | Restart Nginx
2023-03-30 06:20:55 +00:00
copy:
src: 'files/nginx.conf'
dest: '{{ nginx__condf_dir }}/nginx.conf'
mode: 'u=rw,go=r'
owner: root
group: root
2021-09-18 19:37:57 +00:00
- name: Install Nginx log config
notify: nginx | Restart Nginx
copy:
2021-09-20 04:31:45 +00:00
src: 'files/syslog.conf'
2021-09-18 19:37:57 +00:00
dest: '{{ nginx__confd_dir }}/syslog.conf'
mode: 'u=rw,go=r'
owner: root
group: root
- name: Remove Nginx default site
notify: nginx | Restart Nginx
file:
state: absent
path: '{{ nginx__enabled_dir }}/default'
when: nginx__remove_default|bool
- name: Add Nginx upstreams
notify: nginx | Restart Nginx
template:
2021-09-20 04:38:05 +00:00
src: 'templates/upstream.conf'
2021-09-18 19:37:57 +00:00
dest: '{{ nginx__confd_dir }}/upstream-{{ item.name }}.conf'
mode: 'u=rw,go=r'
owner: root
group: root
with_items: '{{ nginx__upstreams }}'
- name: Add Nginx sites
notify: nginx | Restart Nginx
template:
2021-09-20 04:39:11 +00:00
src: 'templates/site.conf'
2021-09-18 19:37:57 +00:00
dest: '{{ nginx__available_dir }}/{{ item.domain }}.conf'
mode: 'u=rw,go=r'
owner: root
group: root
with_items: '{{ nginx__sites }}'
- name: Enable Nginx sites
notify: nginx | Restart Nginx
file:
state: link
src: '{{ nginx__available_dir }}/{{ item.domain }}.conf'
dest: '{{ nginx__enabled_dir }}/{{ item.domain }}.conf'
owner: root
group: root
with_items: '{{ nginx__sites }}'