diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2023-09-01 01:27:09 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2023-09-01 01:27:09 +0200 |
commit | 347803f5a811972c719b09999d4d2b5e9e32e3eb (patch) | |
tree | cd7c5705426ae0ff8a41e84418c5407fbc1ec810 /roles/nginx/tasks/main.yml | |
parent | 7ad67630c40c0669cc1c140ff2d42311fb780b47 (diff) | |
download | ansible_collection-347803f5a811972c719b09999d4d2b5e9e32e3eb.tar.gz |
new nginx role
Diffstat (limited to 'roles/nginx/tasks/main.yml')
-rw-r--r-- | roles/nginx/tasks/main.yml | 52 |
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 |