# platform = multi_platform_all
# reboot = false
# strategy = restrict
# complexity = low
# disruption = low



- name: "Setting unquoted shell-style assignment of 'FirewallBackend' to 'nftables' in '/etc/firewalld/firewalld.conf'"
  block:
    - name: "Check for duplicate values"
      ansible.builtin.lineinfile:
        path: '/etc/firewalld/firewalld.conf'
        create: yes
        regexp: '(?i)^\s*FirewallBackend='
        state: 'absent'
      check_mode: yes
      changed_when: no
      register: 'dupes'
    - name: "Deduplicate values from /etc/firewalld/firewalld.conf"
      ansible.builtin.lineinfile:
        path: '/etc/firewalld/firewalld.conf'
        create: yes
        regexp: '(?i)^\s*FirewallBackend='
        state: 'absent'
      when: 'dupes.found is defined and dupes.found > 1'
    - name: "Insert correct line to /etc/firewalld/firewalld.conf"
      ansible.builtin.lineinfile:
        path: '/etc/firewalld/firewalld.conf'
        create: yes
        regexp: '(?i)^\s*FirewallBackend='
        line: 'FirewallBackend=nftables'
        state: present
        insertbefore: '^# FirewallBackend'
        validate: '/usr/bin/bash -n %s'
