aboutsummaryrefslogtreecommitdiff
path: root/roles/nginx/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'roles/nginx/tasks')
-rw-r--r--roles/nginx/tasks/main.yml52
1 files changed, 52 insertions, 0 deletions
diff --git a/roles/nginx/tasks/main.yml b/roles/nginx/tasks/main.yml
new file mode 100644
index 0000000..f2e4c7a
--- /dev/null
+++ b/roles/nginx/tasks/main.yml
@@ -0,0 +1,52 @@
+---
+- name: Install packages
+ apt:
+ name:
+ - nginx
+ become: true
+
+- name: Install site config
+ template:
+ src: nginx.conf.j2
+ dest: '/etc/nginx/sites-available/{{ item.key }}'
+ become: true
+ with_dict: '{{ nginx.servers }}'
+ notify:
+ - restart nginx
+
+- name: Enable sites
+ file:
+ src: '/etc/nginx/sites-available/{{ item.key }}'
+ dest: '/etc/nginx/sites-enabled/{{ item.key }}'
+ state: link
+ become: true
+ with_dict: '{{ nginx.servers }}'
+ notify:
+ - restart nginx
+
+- name: Find old site links
+ find:
+ paths: '/etc/nginx/sites-enabled/'
+ excludes: '{{ nginx.servers.keys() }}'
+ file_type: link
+ depth: false
+ become: true
+ register: links_to_delete
+
+- name: Find old site files
+ find:
+ paths: '/etc/nginx/sites-available/'
+ excludes: '{{ nginx.servers.keys() }}'
+ file_type: file
+ depth: false
+ become: true
+ register: files_to_delete
+
+- name: Delete old site files and links
+ file:
+ path: "{{ item.path }}"
+ state: absent
+ with_items: "{{ links_to_delete.files + files_to_delete.files }}"
+ become: true
+ notify:
+ - restart nginx