From 347803f5a811972c719b09999d4d2b5e9e32e3eb Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Fri, 1 Sep 2023 01:27:09 +0200 Subject: new nginx role --- roles/nginx/tasks/main.yml | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 roles/nginx/tasks/main.yml (limited to 'roles/nginx/tasks/main.yml') 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 -- cgit v1.2.3