diff --git a/tasks/conf/push-config.yml b/tasks/conf/push-config.yml index 6dd21b6..cbb052e 100644 --- a/tasks/conf/push-config.yml +++ b/tasks/conf/push-config.yml @@ -1,4 +1,22 @@ --- +- name: "(Setup: All NGINX) Check NGINX Default Configuration File Exists" + stat: + path: /etc/nginx/conf.d/default.conf + register: default_exists + +- name: "(Setup: All NGINX) Backup NGINX Default Configuration File" + copy: + remote_src: yes + src: /etc/nginx/conf.d/default.conf + dest: /etc/nginx/conf.d/default.conf.bak + when: default_exists.stat.exists + +- name: "(Setup: All NGINX) Delete NGINX Default Configuration File" + file: + path: /etc/nginx/conf.d/default.conf + state: absent + when: default_exists.stat.exists + - name: "(Setup: All NGINX) Upload NGINX Main Configuration File" copy: src: "{{ main_upload_location }}" @@ -6,19 +24,31 @@ notify: "(Handler: All OSs) Reload NGINX" when: main_upload_enable +- name: "(Setup: All NGINX) Ensure NGINX HTTP Directory Exists" + file: + path: /etc/nginx/conf.d/http + state: directory + when: http_template_enable + - name: "(Setup: All NGINX) Upload NGINX HTTP Configuration Files" copy: src: "{{ item }}" - dest: /etc/nginx/conf.d/ + dest: /etc/nginx/conf.d/http with_fileglob: - "{{ http_upload_location }}" notify: "(Handler: All OSs) Reload NGINX" when: http_upload_enable +- name: "(Setup: All NGINX) Ensure NGINX Stream Directory Exists" + file: + path: /etc/nginx/conf.d/stream + state: directory + when: stream_template_enable + - name: "(Setup: All NGINX) Upload NGINX Stream Configuration Files" copy: src: "{{ item }}" - dest: /etc/nginx/conf.d/ + dest: /etc/nginx/conf.d/stream with_fileglob: - "{{ stream_upload_location }}" notify: "(Handler: All OSs) Reload NGINX" diff --git a/tasks/conf/setup-status.yml b/tasks/conf/setup-status.yml index c8258e9..1b1a4a9 100644 --- a/tasks/conf/setup-status.yml +++ b/tasks/conf/setup-status.yml @@ -1,7 +1,7 @@ --- - name: "(Setup: Open Source NGINX) Enable Open Source NGINX Status" blockinfile: - path: /etc/nginx/conf.d/stub_status.conf + path: "{{ (http_template_enable) | ternary('/etc/nginx/conf.d/http/stub_status.conf','/etc/nginx/conf.d/stub_status.conf') }}" create: yes block: | server { @@ -17,7 +17,7 @@ - name: "(Setup: NGINX Plus) Enable NGINX Plus Status" blockinfile: - path: /etc/nginx/conf.d/status.conf + path: "{{ (http_template_enable) | ternary('/etc/nginx/conf.d/http/status.conf','/etc/nginx/conf.d/status.conf') }}" create: yes block: | server { diff --git a/tasks/conf/template-config.yml b/tasks/conf/template-config.yml index 46490ec..5d54b77 100644 --- a/tasks/conf/template-config.yml +++ b/tasks/conf/template-config.yml @@ -1,22 +1,54 @@ --- +- name: "(Setup: All NGINX) Check NGINX Default Configuration File Exists" + stat: + path: /etc/nginx/conf.d/default.conf + register: default_exists + +- name: "(Setup: All NGINX) Backup NGINX Default Configuration File" + copy: + remote_src: yes + src: /etc/nginx/conf.d/default.conf + dest: /etc/nginx/conf.d/default.conf.bak + when: default_exists.stat.exists + +- name: "(Setup: All NGINX) Delete NGINX Default Configuration File" + file: + path: /etc/nginx/conf.d/default.conf + state: absent + when: default_exists.stat.exists + - name: "(Setup: All NGINX) Dynamically Generate NGINX Main Configuration File" template: src: nginx.conf.j2 dest: /etc/nginx/nginx.conf notify: "(Handler: All OSs) Reload NGINX" +- name: "(Setup: All NGINX) Ensure NGINX HTTP Directory Exists" + file: + path: /etc/nginx/conf.d/http + state: directory + when: http_template_enable + - name: "(Setup: All NGINX) Dynamically Generate NGINX HTTP Configuration Files" template: src: "{{ item }}" - dest: /etc/nginx/conf.d/{{ item | basename | regex_replace('\.j2','') }} + dest: /etc/nginx/conf.d/http/{{ item | basename | regex_replace('\.j2','') }} with_fileglob: - "../templates/http/*.j2" + when: http_template_enable notify: "(Handler: All OSs) Reload NGINX" +- name: "(Setup: All NGINX) Ensure NGINX Stream Directory Exists" + file: + path: /etc/nginx/conf.d/stream + state: directory + when: stream_template_enable + - name: "(Setup: All NGINX) Dynamically Generate NGINX Stream Configuration Files" template: src: "{{ item }}" - dest: /etc/nginx/conf.d/{{ item | basename | regex_replace('\.j2','') }} + dest: /etc/nginx/conf.d/stream/{{ item | basename | regex_replace('\.j2','') }} with_fileglob: - "../templates/stream/*.j2" + when: stream_template_enable notify: "(Handler: All OSs) Reload NGINX"