- name: Install smartmontools package
  apt: pkg=smartmontools state=installed update_cache=yes
  when: with_smartd

- name: Install smartd configuration
  template: dest=/etc/smartd.conf owner=root group=root mode=0644
  first_available_file:
    - smartd/smartd.{{ ansible_hostname }}.conf.j2
    - smartd/smartd.conf.j2
  notify:
    - Restart smartmontools
  when: with_smartd

- name: Update smartmontools default/init parameters
  template: src=smartd/default.j2 dest=/etc/default/smartmontools owner=root group=root mode=0644
  notify:
    - Restart smartmontools
  when: with_smartd

- name: Ensure smartmontools is running
  service: name=smartmontools state=started
  when: with_smartd