---
- when: ipsec_uninstall_tunnels|bool or ipsec_upgrade_tunnels|bool
  block:
  - import_tasks: uninstall.yml

- when: not ipsec_uninstall_tunnels|bool or ipsec_upgrade_tunnels|bool
  block:
  - import_tasks: setup.yml

  - import_tasks: firewall.yml
    when: not ipsec_skip_firewall_rules|bool

  - meta: flush_handlers

  # This doesn't use the dynamic inventory
  - import_tasks: legacy.yml
    when: enabled_networks is not defined or ipsec_force_install_legacy|bool

  # This uses the dynamic inventory
  - import_tasks: ipsec.yml
    when: enabled_networks is defined and not ipsec_force_install_legacy|bool
