Ask Your Question

How to do something based on a facter(IP address)

asked 2015-07-24 14:39:10 -0600

kartikv gravatar image


I would like to take an action based on if the ipaddress dfrom facter is in the subnet 192.168 and another action if the IP address from facter is in the subnet 192.169.

Please advise. Regards,


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-07-25 02:20:08 -0600

I'm guessing what you mean is you want to take action based on whether or not the IP or network address starts with 192.168 or 192.169 (that's not the same as a subnet).

In which case you can do this:

if $::ipaddress =~ /^192.168/ {
  # do something
elsif $::ipaddress =~ /^192.169/ {
  # do something else
else {
  fail("don't know what to do with IP address $::ipaddress")
edit flag offensive delete link more


Thank you very very much. That's exactly what I needed. I appreciate your help. Regards, Kartik Vashishta

kartikv gravatar imagekartikv ( 2015-07-25 10:49:57 -0600 )edit

@Alex Harvey: Can you please explain your code ? After a If condition, How we could do conditional operators ? can you please share me any documentation ?

ArunRaj Rajavel gravatar imageArunRaj Rajavel ( 2016-02-07 22:41:08 -0600 )edit
Alex Harvey gravatar imageAlex Harvey ( 2016-02-07 23:05:08 -0600 )edit

@Alex Harvey : Thanks for the cool article.

ArunRaj Rajavel gravatar imageArunRaj Rajavel ( 2016-02-08 01:26:24 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-07-24 14:39:10 -0600

Seen: 2,480 times

Last updated: Jul 25 '15