Question

I am just thinking is there a way of getting the private Ip of the machine and using that in our puppet script, so let suppose we have the script to show the IP as:

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

How can I get the private Ip in the file?

Was it helpful?

Solution

What do you mean by private ip of the machine ?

If you have facter installed, you can do,

 facter --puppet 

to get a list of facts about the machines. Many of these facts will point to ipaddresses and other network parameters used by the machine.

 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

In your code you can do,

 $my_ip = $::ipaddress
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top