2025-02-18 04:07:07 +01:00
|
|
|
- name: Check, if a save of a previous `nginx.conf` is present
|
2023-04-15 18:13:22 +02:00
|
|
|
ansible.builtin.stat:
|
|
|
|
path: /etc/nginx/nginx.conf.ansiblesave
|
2025-02-18 04:07:07 +01:00
|
|
|
register: nginx__nginx_conf_ansiblesave_stat
|
2023-04-15 18:13:22 +02:00
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Handle the case, where a custom `nginx.conf` is to be used
|
2023-04-15 18:13:22 +02:00
|
|
|
when: nginx__use_custom_nginx_conf
|
|
|
|
block:
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: When no `nginx.conf.ansiblesave` is present, save the current `nginx.conf`
|
|
|
|
when: not nginx__nginx_conf_ansiblesave_stat.stat.exists
|
2023-04-15 18:13:22 +02:00
|
|
|
ansible.builtin.copy:
|
|
|
|
force: true
|
|
|
|
dest: /etc/nginx/nginx.conf.ansiblesave
|
2024-11-23 02:49:23 +01:00
|
|
|
mode: "0644"
|
2023-04-15 18:13:22 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
remote_src: true
|
|
|
|
src: /etc/nginx/nginx.conf
|
|
|
|
become: true
|
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Ensure the custom `nginx.conf` is deployed
|
2023-04-15 18:13:22 +02:00
|
|
|
ansible.builtin.copy:
|
|
|
|
content: "{{ nginx__custom_nginx_conf }}"
|
|
|
|
dest: "/etc/nginx/nginx.conf"
|
2024-11-23 02:49:23 +01:00
|
|
|
mode: "0644"
|
2023-04-15 18:13:22 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
become: true
|
2025-02-18 04:07:07 +01:00
|
|
|
notify: Restart nginx
|
2023-04-15 18:13:22 +02:00
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Handle the case, where no custom `nginx.conf` is to be used
|
2023-04-15 18:13:22 +02:00
|
|
|
when: not nginx__use_custom_nginx_conf
|
|
|
|
block:
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: When a `nginx.conf.ansiblesave` is present, copy it to `nginx.conf`
|
|
|
|
when: nginx__nginx_conf_ansiblesave_stat.stat.exists
|
2023-04-15 18:13:22 +02:00
|
|
|
ansible.builtin.copy:
|
|
|
|
force: true
|
|
|
|
dest: /etc/nginx/nginx.conf
|
2024-11-23 02:49:23 +01:00
|
|
|
mode: "0644"
|
2023-04-15 18:13:22 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
remote_src: true
|
|
|
|
src: /etc/nginx/nginx.conf.ansiblesave
|
|
|
|
become: true
|
2025-02-18 04:07:07 +01:00
|
|
|
notify: Restart nginx
|
2023-04-15 18:13:22 +02:00
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Ensure no `nginx.conf.ansiblesave` is present
|
|
|
|
when: nginx__nginx_conf_ansiblesave_stat.stat.exists
|
2023-04-15 18:13:22 +02:00
|
|
|
ansible.builtin.file:
|
|
|
|
path: /etc/nginx/nginx.conf.ansiblesave
|
|
|
|
state: absent
|
|
|
|
become: true
|
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Ensure mozilla dhparam is deployed
|
2023-04-15 18:13:22 +02:00
|
|
|
ansible.builtin.get_url:
|
|
|
|
force: true
|
|
|
|
dest: /etc/nginx-mozilla-dhparam
|
2024-11-23 02:49:23 +01:00
|
|
|
mode: "0644"
|
2023-04-15 18:13:22 +02:00
|
|
|
url: https://ssl-config.mozilla.org/ffdhe2048.txt
|
|
|
|
become: true
|
2025-02-18 04:07:07 +01:00
|
|
|
notify: Restart nginx
|
2023-04-15 18:13:22 +02:00
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Set `nginx__config_files_to_exist` fact initially to an empty list
|
2023-04-15 18:13:22 +02:00
|
|
|
ansible.builtin.set_fact:
|
|
|
|
nginx__config_files_to_exist: [ ]
|
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Handle the case, where tls.conf should be deployed
|
2023-04-15 18:13:22 +02:00
|
|
|
when: nginx__deploy_tls_conf
|
|
|
|
block:
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Ensure tls.conf is deployed
|
2023-04-15 18:13:22 +02:00
|
|
|
ansible.builtin.copy:
|
|
|
|
force: true
|
|
|
|
dest: /etc/nginx/conf.d/tls.conf
|
2024-11-23 02:49:23 +01:00
|
|
|
mode: "0644"
|
2023-04-15 18:13:22 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
src: tls.conf
|
|
|
|
become: true
|
2025-02-18 04:07:07 +01:00
|
|
|
notify: Restart nginx
|
2023-04-15 18:13:22 +02:00
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Add tls.conf to nginx__config_files_to_exist
|
2023-04-15 18:13:22 +02:00
|
|
|
ansible.builtin.set_fact:
|
|
|
|
nginx__config_files_to_exist: "{{ nginx__config_files_to_exist + [ 'tls.conf' ] }}" # noqa: jinja[spacing]
|
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Handle the case, where redirect.conf should be deployed
|
2023-04-15 18:13:22 +02:00
|
|
|
when: nginx__deploy_redirect_conf
|
|
|
|
block:
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Ensure redirect.conf is deployed
|
2023-04-15 18:13:22 +02:00
|
|
|
ansible.builtin.copy:
|
|
|
|
force: true
|
|
|
|
dest: /etc/nginx/conf.d/redirect.conf
|
2024-11-23 02:49:23 +01:00
|
|
|
mode: "0644"
|
2023-04-15 18:13:22 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
src: redirect.conf
|
|
|
|
become: true
|
2025-02-18 04:07:07 +01:00
|
|
|
notify: Restart nginx
|
2023-04-15 18:13:22 +02:00
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Add redirect.conf to nginx__config_files_to_exist
|
2023-04-15 18:13:22 +02:00
|
|
|
ansible.builtin.set_fact:
|
|
|
|
nginx__config_files_to_exist: "{{ nginx__config_files_to_exist + [ 'redirect.conf' ] }}" # noqa: jinja[spacing]
|
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Handle the case, where logging.conf should be deployed
|
2025-01-19 20:30:53 +01:00
|
|
|
when: nginx__deploy_logging_conf
|
|
|
|
block:
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Ensure logging.conf is deployed
|
2025-01-19 20:30:53 +01:00
|
|
|
ansible.builtin.copy:
|
|
|
|
force: true
|
|
|
|
dest: /etc/nginx/conf.d/logging.conf
|
|
|
|
mode: "0644"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
src: logging.conf
|
|
|
|
become: true
|
2025-02-18 04:07:07 +01:00
|
|
|
notify: Restart nginx
|
2025-01-19 20:30:53 +01:00
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Add logging.conf to nginx__config_files_to_exist
|
2025-01-19 20:30:53 +01:00
|
|
|
ansible.builtin.set_fact:
|
|
|
|
nginx__config_files_to_exist: "{{ nginx__config_files_to_exist + [ 'logging.conf' ] }}" # noqa: jinja[spacing]
|
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Ensure all given configuration files are deployed
|
2023-04-15 18:13:22 +02:00
|
|
|
ansible.builtin.copy:
|
|
|
|
content: "{{ item.content }}"
|
|
|
|
dest: "/etc/nginx/conf.d/{{ item.name }}.conf"
|
2024-11-23 02:49:23 +01:00
|
|
|
mode: "0644"
|
2023-04-15 18:13:22 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
become: true
|
|
|
|
loop: "{{ nginx__configurations }}"
|
2025-02-18 06:07:47 +01:00
|
|
|
loop_control:
|
|
|
|
label: "{{ item.name }}"
|
2025-02-18 04:07:07 +01:00
|
|
|
notify: Restart nginx
|
2023-04-15 18:13:22 +02:00
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Add names with suffixes from `nginx__configurations` to `nginx__config_files_to_exist` fact
|
2023-04-15 18:13:22 +02:00
|
|
|
ansible.builtin.set_fact:
|
|
|
|
nginx__config_files_to_exist: "{{ nginx__config_files_to_exist + [ item.name + '.conf' ] }}" # noqa: jinja[spacing]
|
|
|
|
loop: "{{ nginx__configurations }}"
|
2025-02-18 06:07:47 +01:00
|
|
|
loop_control:
|
|
|
|
label: "{{ item.name }}"
|
2023-04-15 18:13:22 +02:00
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Find configuration files to remove
|
2023-04-15 18:13:22 +02:00
|
|
|
ansible.builtin.find:
|
|
|
|
paths: /etc/nginx/conf.d/
|
|
|
|
recurse: false
|
|
|
|
excludes: "{{ nginx__config_files_to_exist }}"
|
|
|
|
register: nginx__config_files_to_remove
|
|
|
|
|
2025-02-18 04:07:07 +01:00
|
|
|
- name: Remove all configuration file, which should be removed
|
2023-04-15 18:13:22 +02:00
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ item.path }}"
|
|
|
|
state: absent
|
|
|
|
become: true
|
|
|
|
loop: "{{ nginx__config_files_to_remove.files }}"
|
2025-02-18 06:07:47 +01:00
|
|
|
loop_control:
|
|
|
|
label: "{{ item.path | ansible.builtin.basename }}"
|
2025-02-18 04:07:07 +01:00
|
|
|
notify: Restart nginx
|