如何从master获取salt-minion的公共ip地址?

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" ] 

}

我使用salt.modules.network来查找私有IP地址,但我没有find如何从小伙伴获得公共IP地址。

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

我用这个文档。 我需要公共知识产权来确定盐是否正常工作。

通过运行你得到的小众的公共IP地址:

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

你可以在这里find更多的细节: https : //serverfault.com/a/616423/53467

什么pincoded说的作品,但如果有人后来绊倒了这一点,你也可以有外部的IP作为粮食:

 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} 

来自: https : //gist.github.com/jfrost/7894718