---
# Test playbook for the firewalld module
# (c) 2017, Adam Miller <admiller@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

- name: Run firewalld tests
  when:
    - ansible_facts.os_family == "RedHat" and ansible_facts.distribution_major_version is version('7', '>=')
    - not (ansible_distribution == "Ubuntu" and ansible_distribution_version is version('14.04', '=='))
    # Firewalld package on OpenSUSE (15+) require Python 3, so we skip on OpenSUSE running py2 on these newer distros
    - not (ansible_os_family == "Suse" and ansible_distribution_major_version|int != 42 and ansible_python.version.major != 3)
    - not (ansible_facts.distribution == "CentOS" and ansible_distribution_major_version is version('7', '==')) # FIXME
  block:
    - name: Ensure firewalld is installed
      ansible.builtin.package:
        name: firewalld
        state: present
    # This doesn't work for CentOS 6 because firewalld doesn't exist in CentOS6

    - name: Enable dbus-broker daemon
      ansible.builtin.service:
        name: dbus-broker
        enabled: true
        state: started
      when: (ansible_distribution == 'Fedora' and ansible_distribution_major_version is version('34', '=='))

    - name: Test Online Operations
      block:
        - name: Start firewalld
          ansible.builtin.service:
            name: firewalld
            state: started

        - name: Import test tasks
          ansible.builtin.import_tasks: run_all_tests.yml

    - name: Test Offline Operations
      block:
        - name: Stop firewalld
          ansible.builtin.service:
            name: firewalld
            state: stopped

        - name: Import test tasks
          ansible.builtin.import_tasks: run_all_tests.yml
