我只是想有办法获取机器的私有IP并在我们的puppet脚本中使用它,所以让我们假设我们有脚本将IP显示为:
class test{
$my_ip=<some code>
file{'print_ip_to_my_file':
path => "/tmp/ip.txt",
content => "This is test file and the private ip is : ${my_ip}"
}
}
如何在文件中获取私有IP ?
答案 0 :(得分:14)
你对机器的私人IP是什么意思?
如果你安装了facter,你可以这样做,
facter --puppet
获取有关机器的事实列表。其中许多事实将指向机器使用的ipaddresses和其他网络参数。
facter --puppet | grep ipaddress
ipaddress => xxx.yy.zz.abc
ipaddress_eth0 => xxx.yy.zz.abc
ipaddress_lo => 127.0.0.1
facter --puppet | grep network
在您的代码中,您可以这样做,
$my_ip = $::ipaddress