- hosts: nas name: Sync mailu ignore_unreachable: false vars: app_path: "{{ 'localhost:80' | regex_replace('^(?P.+):(?P\\d+)$', '\\g111, \\g') }}" tasks: - name: Print the gateway for each host when defined ansible.builtin.debug: msg: var is "{{ app_path }}"