---
- name: Install and enable the nginx virtualhost files on RH based systems
  when: ansible_distribution_file_variety == "RedHat"
  tags: [nginx, virtualhost]
  block:
    - name: Create stream.d directory
      ansible.builtin.file:
        path: /etc/nginx/stream.d
        state: directory
        owner: root
        group: root
        mode: "0644"

    - name: Install the nginx stream files
      ansible.builtin.template:
        src: nginx-stream.conf.j2
        dest: /etc/nginx/stream.d/{{ item.stream }}.conf
        owner: root
        group: root
        mode: "0644"
      loop: "{{ nginx_streams }}"
      notify: Reload nginx
