--- - name: setup nginx base configuration become: true ansible.builtin.template: src: templates/nginx/nginx.conf.j2 dest: /etc/nginx/nginx.conf owner: root group: http mode: 0644 notify: restart_nginx tags: http - name: setup nginx directories become: true ansible.builtin.file: path: "/etc/nginx/{{ item }}" state: directory mode: 0755 loop: - sites-enabled - sites-available tags: http - name: ensure http and letsencrypt directories exist become: true ansible.builtin.file: path: "{{ item }}" state: directory owner: http group: http mode: 0755 loop: - /srv/http - /srv/http/letsencrypt tags: http - name: chown http user home become: true ansible.builtin.file: path: /srv/http owner: http group: http mode: 0755 recurse: true tags: http - name: template nginx http sites-available become: true ansible.builtin.template: src: "templates/nginx/sites/{{ item }}.j2" dest: "/etc/nginx/sites-available/{{ item }}" mode: 0644 loop: - "{{ ci_server_name }}.http.conf" - "{{ pi_server_name }}.conf" - "{{ home_server_name }}.conf" - "{{ assistant_server_name }}.conf" - "{{ video_server_name }}.conf" - "{{ parts_server_name }}.conf" - "{{ logs_server_name }}.conf" notify: restart_nginx tags: http - name: remove pihole from sites-enabled if there become: true ansible.builtin.file: path: "/etc/nginx/sites-enabled/pi.hole.conf" state: absent tags: http - name: enable desired nginx http sites become: true ansible.builtin.file: src: "/etc/nginx/sites-available/{{ item }}" dest: "/etc/nginx/sites-enabled/{{ item }}" state: link loop: - "{{ ci_server_name }}.http.conf" - "{{ pi_server_name }}.conf" - "{{ parts_server_name }}.conf" - "{{ home_server_name }}.conf" - "{{ assistant_server_name }}.conf" - "{{ video_server_name }}.conf" - "{{ logs_server_name }}.conf" notify: restart_nginx tags: http - name: validate nginx configurations become: true ansible.builtin.command: nginx -t changed_when: false tags: http