---
- name: "Nginx | Set websrv specific variables"
  ansible.builtin.set_fact:
    zabbix_web_user: "{{ zabbix_web_user if zabbix_web_user is defined else _nginx_user }}"
    zabbix_web_group: "{{ zabbix_web_group if zabbix_web_group is defined else _nginx_group }}"
    zabbix_web_vhost_location: "{{ zabbix_web_vhost_location if zabbix_web_vhost_location is defined else _nginx_vhost_location }}"
    zabbix_nginx_log_path: "{{ zabbix_nginx_log_path if zabbix_nginx_log_path is defined else _nginx_log_path }}"
    zabbix_nginx_service: "{{ zabbix_nginx_service if zabbix_nginx_service is defined else _nginx_service }}"
  tags:
    - config
    - install

- name: "Nginx | Installing Zabbix Nginx Conf"
  package:
    name: "{{ _zabbix_web_nginx_packages + _zabbix_web_nginx_php_dependencies | default([]) }}"
    state: "{{ zabbix_web_package_state }}"
    update_cache: true
    disablerepo: "{{ zabbix_web_disable_repo | default(_zabbix_web_disable_repo | default(omit)) }}"
  environment:
    http_proxy: "{{ zabbix_http_proxy | default(None) | default(omit) }}"
    https_proxy: "{{ zabbix_https_proxy | default(None) | default(omit) }}"
  register: zabbix_nginx_conf_install
  until: zabbix_nginx_conf_install is succeeded
  become: true
  tags:
    - install

- name: "Nginx | Install vhost in conf.d"
  ansible.builtin.template:
    src: nginx_vhost.conf.j2
    dest: "{{ zabbix_web_vhost_location }}"
    owner: "{{ zabbix_web_user }}"
    group: "{{ zabbix_web_group }}"
    mode: 0644
  when:
    - zabbix_web_create_vhost
  become: true
  notify:
    - restart nginx
  tags:
    - config
