How to get the public ip address of salt-minion from master

saltstack

root@I-Kod:/home/i-kod/Desktop/ass1# salt '*' network.ip_addrs
{
   "I-Kod": [
       "10.0.1.215"
   ]
}
 {
   "neha-HP-Pavilion-15-Notebook-PC": [
    "10.0.0.231"
   ]
  }
  {
      "Pavilion": [
          "10.0.1.214"
   ]
  }
  {
      "Pavilion": [
          "10.0.1.214"
   ]

}

I used the salt.modules.network for finding the private IP address but I didnt find how to get the public IP address with salt-master from minions.

http://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.network.html

I used this documentation. I require public IP to determine whether salt is correctly working or not.

Best Answer

What pincoded said works, but in case someone stumbles onto this later on, you can also have the external IP as a grain:

import requests

def external_ip():
    """
    Return the external IP address reported by ipecho.net
    """
    try:
        r = requests.get('http://ipecho.net/plain')
        ip = r.content
    except:
        ip = ''
    return {'external_ip': ip}

from: https://gist.github.com/jfrost/7894718