How to get IP address of hostname inside jinja template
This is a very old post, but it is highly ranked in Google for getting the ipv4 address.  As of salt 2015.5.8, the best way to get the primary ipv4 address is {{ grains['ipv4'][0] }}.
Our saltstack is based on hostnames (webN., dbN., etc.). But for various things I need IPs of those servers. For now I had them stored in pillars, but the number of places I need to sync grows. 
I tried to use publish + network.ip_addrs, but that kinda sucks, because it needs to do the whole salt-roundtrip just to resolve a hostname. Also it's dependent on the minions responding. Therefore I'm looking for a way to resolve hostname to IP in templates. 
I assume that I could write a module for it somehow, but my python skills are very limited.