---
- name: install automake
  yum: name=automake state=present
  become: true
  become_user: root
  when: ansible_os_family=='RedHat'

- name: install automake
  apt: name=automake state=present
  become: true
  become_user: root
  when: ansible_os_family=='Debian'

- name: unarchive nhc
  unarchive:
  args:
    src: "https://github.com/mej/nhc/archive/{{ nhc_version }}.tar.gz"
    copy: no
    dest: /tmp
    creates: /tmp/nhc-{{ nhc_version }}/autogen.sh

- name: build nhc 
  shell: ./autogen.sh && ./configure --prefix={{ nhc_dir }} && make
  args:
    chdir: /tmp/nhc-{{ nhc_version }}
    creates: /tmp/nhc-{{ nhc_version }}/configure

- name: install nhc 
  shell: make install
  sudo: true
  args:
      chdir: /tmp/nhc-{{ nhc_version }}

- name: ensure sysconfig dir exists
  file: dest=/etc/sysconfig state=directory owner=root group=root mode=755
  sudo: true

- name: copy nhc sysconfig script
  template: dest=/etc/sysconfig/nhc src=nhc.sysconfig.j2 mode=644
  sudo: true

- name: copy nhc log rotate script
  template: dest=/etc/logrotate.d/nhc src=nhclog.j2 mode=644
  sudo: true

- name: install nhc config file
  copy: src=nhc.conf dest={{ nhc_dir }}/etc/nhc/{{ nhc_config_file }}
  become: true
  become_user: root

- name: install nhc scripts
  copy: src=scripts/ dest={{ nhc_dir }}/etc/nhc/
  become: true
  become_user: root
