--- - name: Check if network interface has an IP address in public_network ansible.builtin.fail: msg: "{{ inventory_hostname }} does not have any {{ ip_version }} address on {{ public_network }}" when: hostvars[inventory_hostname]['ansible_facts']['all_' + ip_version + '_addresses'] | ips_in_ranges(hostvars[inventory_hostname]['public_network'].split(',')) | length == 0