- name: start and enable pffirewall
  tags: pffirewall
  become: true
  service:
     name: pffirewall
     state: started
     enabled: true
  # run as an asynchronous task, so Ansible will not wait for end of the command:
  async: 1
  # Ansible will never poll if the command has finished - it will make this command a "fire and forget":
  poll: 0
  # async will fail in check mode. somply not execute this handler:
  when: not ansible_check_mode
  listen: "start and enable pffirewall"

- name: wait after start and enable pffirewall
  tags: pffirewall
  local_action:
    module: ansible.builtin.wait_for
      timeout=4
  # no need to wait without reason:
  when: not ansible_check_mode
  listen: "start and enable pffirewall"


- name: restart pffirewall
  tags: pffirewall
  become: true
  service:
    name: pffirewall
    state: restarted
    enabled: true
  # run as an asynchronous task, so Ansible will not wait for end of the command:
  async: 1
  # Ansible will never poll if the command has finished - it will make this command a "fire and forget":
  poll: 0
  # async will fail in check mode. somply not execute this handler:
  when: not ansible_check_mode
  listen: "restart pffirewall"

- name: wait after restart pffirewall
  tags: pffirewall
  local_action:
    module: ansible.builtin.wait_for
      timeout=4
  # no need to wait without reason:
  when: not ansible_check_mode
  listen: "restart pffirewall"
