mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #9144 from jfrost/external_ip_grain
new external_ip grain for salt - requires that requests be installed
This commit is contained in:
commit
0923aed4d3
20
salt/grains/external_ip.py
Normal file
20
salt/grains/external_ip.py
Normal file
@ -0,0 +1,20 @@
|
||||
try:
|
||||
import requests
|
||||
HAS_REQUESTS = True
|
||||
except:
|
||||
HAS_REQUESTS = False
|
||||
|
||||
def external_ip():
|
||||
'''
|
||||
Return the external IP address reported by ipecho.net
|
||||
'''
|
||||
|
||||
if not HAS_REQUESTS:
|
||||
return []
|
||||
|
||||
try:
|
||||
r = requests.get('http://ipecho.net/plain')
|
||||
ip = r.content
|
||||
except:
|
||||
ip = []
|
||||
return {'external_ip': ip}
|
Loading…
Reference in New Issue
Block a user