---
- name: Copying .deb to remote
  when: ansible_os_family == "Debian"
  copy:
    src: files/endlesshgo-amd64.deb
    dest: /root/endlesshgo-amd64.deb
    mode: '0744'
  tags:
    - endlessh

- name: Install endlessh-go to remote
  when: ansible_os_family == "Debian"
  apt:
    deb: /root/endlesshgo-amd64.deb
  tags:
    - endlessh

- name: Enable and start the endlessh-go service
  block:
    - systemd:
        name: endlessh-go
        state: enabled
    - systemd:
        name: endlessh-go
        state: restarted
  tags:
    - endlessh

- name: Populate service_facts
  service_facts:
  tags:
    - endlessh

- name: Open Firewalld ports
  block:
    - firewalld:
        port: "{{ item.value.port }}"
        zone: "{{ item.value.zone }}"
        permanent: yes
        state: enabled
      loop: "{{ lookup('dict', fwd_ports) }}"
    - systemd:
        name: firewalld
        state: reloaded
  when: "'firewalld.service' in ansible_facts.services" 
  tags:
    - endlessh



