3
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.

I-Kod
  • 31
  • 1
  • 1
  • 3

3 Answers3

6

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

pepoluan
  • 5,038
  • 4
  • 47
  • 72
savamane
  • 91
  • 2
5

You get the public ip address of the minions by running:

salt '*' cmd.run "curl http://ipecho.net/plain"

You can find more details here: https://serverfault.com/a/616423/53467

pincoded
  • 369
  • 2
  • 9
  • 1
    Yes I used `salt '*' cmd.run "curl -s checkip.dyndns.org |sed -e 's/.*Current IP Address: //' -e 's/<.*$//' ` Thank You @pincoded – I-Kod Aug 28 '15 at 06:43
  • 1
    Alternatively: `salt '*' cmd.run "wget -qO- http://ipecho.net/plain"` – pepoluan Nov 15 '16 at 05:10
0

You can do this on for salt>= 2015

salt '' cmd.run "facter ipaddress"

example : salt 'mysqlhost01' cmd.run "facter ipaddress"