---
- name: "Ensure {{ app_name }} is installed"
  become: false
  community.general.homebrew:
    name: nginx
    state: "{{ app_state | default('present') }}"

- name: Ensure cmake is installed
  become: false
  community.general.homebrew:
    name: cmake
    state: present
  when: enable_nginx_brotli

- name: Ensure Brotli's dependencies are installed
  become: false
  community.general.homebrew_cask:
    name: "{{ brotli_dependencies }}"
    state: present
    accept_external_apps: "{{ allow_external_apps | default(false) }}"
  when: enable_nginx_brotli

- name: Ensure ModSecurity's dependencies are installed
  become: false
  community.general.homebrew_cask:
    name: "{{ modsec_dependencies }}"
    state: present
    accept_external_apps: "{{ allow_external_apps | default(false) }}"
  when: enable_nginx_modsecurity_waf

- name: Run generic Linux tasks
  include_tasks: install-Linux.yml

- name: Deploy NGINX job definition
  template:
    src: homebrew.nginx.plist.j2
    dest: "{{ nginx_service_path }}"
    owner: root
    mode: 0644

- name: Run NGINX # noqa 301
  command: brew services start nginx
  environment:
    PATH: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:{{ ansible_env.PATH }}
