ip -4 route get 8.8.8.8
was not working on my server.
I created this work around.
- name: find default ipv4... this is a bit of a hack.
shell: ifconfig $(route | grep default | awk '{print $(NF)}') | grep 'inet' | awk '{ print $2}'
register: ipv4_address
Now I can use ipv4_address
wherever needed!