---

- name: Download NCPA v3
  get_url:
    url: https://assets.nagios.com/downloads/ncpa3/ncpa-latest.x86_64.dmg
    dest: /tmp/ncpa.dmg
    force: yes
  
- name: Mount NCPA Installer
  shell: hdiutil attach /tmp/ncpa.dmg

- name: Install NCPA
  shell: zsh /Volumes/NCPA*/install.sh

- name: Set NCPA Token
  lineinfile:
    dest: /usr/local/ncpa/etc/ncpa.cfg
    regexp: ^community_string
    line: "community_string = {{ ncpa_token }}"

- name: Stop NCPA
  shell: launchctl unload /Library/LaunchDaemons/com.nagios.ncpa.plist

- name: Start NCPA
  shell: launchctl load /Library/LaunchDaemons/com.nagios.ncpa.plist

- name: Unmount NCPA Installer
  shell: hdiutil unmount /Volumes/NCPA*

- name: Clean up temp files
  file:
    path: /tmp/ncpa.dmg
    state: absent
