Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the private ip of the machine in Puppet

Tags:

linux

puppet

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?

like image 528
Ankur Verma Avatar asked Dec 07 '22 02:12

Ankur Verma


1 Answers

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
like image 189
iamauser Avatar answered Jan 02 '23 22:01

iamauser