---

- name: Download NCPA (i86 systems)
  get_url:
    url: https://assets.nagios.com/downloads/ncpa/ncpa-latest.sol{{ ansible_distribution_version.split('.')[0] }}.i86pc.pkg
    dest: /tmp/ncpa.pkg
    force: yes
  when: (ansible_architecture not in ['sun4v','sun4u'])

- name: Download NCPA (SPARC systems)
  get_url:
    url: https://assets.nagios.com/downloads/ncpa/ncpa-latest.sol{{ ansible_distribution_version.split('.')[0] }}.sparc.pkg
    dest: /tmp/ncpa.pkg
  when: (ansible_architecture in ['sun4v','sun4u'])

- name: Install NCPA (pkg on Solaris)
  shell: "yes | /usr/sbin/pkgadd -d /tmp/ncpa.pkg ncpa"

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

- name: Restart NCPA
  service:
    name: ncpa
    state: restarted
    enabled: yes

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