---
- name: Prepare
  hosts: all
  become: yes
  vars:
    avahi_packages_redhat:
      - "avahi"
      - "nss-mdns"
    avahi_packages_debian:
      - "avahi-daemon"
      - "avahi-discover"
      - "libnss-mdns"
  tasks:

  - name: Ensure epel is available
    yum:
      name: epel-release
      state: present
    when: ansible_os_family == "RedHat"

  - name: Install avahi packages
    package:
      name: "{{ avahi_packages_redhat }}"
      state: present
    when: ansible_os_family == "RedHat"

  - name: Install avahi packages
    package:
      name: "{{ avahi_packages_debian }}"
      state: present
    when: ansible_os_family == "Debian"

  # debian-stretch seems to require a reboot for avahi-daemon to run
  - name: Reboot host
    reboot:

  - name: Ensure  avahi-daemon is started
    service:
      name: avahi-daemon
      state: started
