- name: Update nginx stream configuration
  hosts: yellow
  vars_files:
    - vars.yaml
  tasks:
  - name: Ensure nginx, certbot, and nginx-mod-stream are installed
    ansible.builtin.dnf:
      name:
        - nginx
        - nginx-mod-stream
      state: present
  - name: Remove http.d dir before repopulating
    file:
      path: /etc/nginx/http.d/
      state: absent
  - name: Remove stream.d dir before repopulating
    file:
      path: /etc/nginx/stream.d/
      state: absent
  - name: Create stream.d dir
    ansible.builtin.file:
      path: /etc/nginx/stream.d
      state: directory
      mode: '0755'
  - name: Template nginx.conf
    template:
      src: nginx.conf
      dest: /etc/nginx/nginx.conf
      owner: root
      group: root
      mode: '0644'
  - name: Test nginx configuration
    ansible.builtin.shell: /usr/sbin/nginx -t
  - name: Stop nginx service
    ansible.builtin.systemd_service:
      state: stopped
      name: nginx
  - name: Reload nginx service
    ansible.builtin.systemd_service:
      state: started
      name: nginx
      enabled: true
