Ask Your Question

How to get remote node ip via regexp

asked 2017-07-03 06:23:26 -0600

glavriba gravatar image

Hi all!

My node's have several ip address. And i need to get and only 192.168.. and use it in my .erb template file. Example: server has ip and In my manifest i write:

if $::ipaddress =~ /^192\.168\.\d{1,3}\.\d{1,3}/ {
else {
  warning("don't know what to do with IP address $::ipaddress")

and in templates: ListenAddress <%= @ipaddress %>

In result, on the nodes conf file i get: ListenAddress

but i have to get ListenAddress

Can anybody can explain me how to do it ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-07-08 08:42:08 -0600

ipaddress is a legacy fact. Don't use it anymore. Instead you need a current Puppet (and Facter) set-up. Then you can access the networking fact and do something like the following:

# only run on nodes with current version of facter(8)
if $::facts['networking'] == undef {
    fail(sprintf('%s: needs current version of facter(8)', $module_name))

$_local_addresses = $::facts['networking']['interfaces'].filter() |$n, $c| {
    # you only need to check for the beginning, don't you?
    $c['ip'] =~ /^192\.168\./

if $_local_addresses != [] {
    file { 'foo':
        # ...
} else {
    warning(sprintf('%s: no local addresses configured', $module_name))

And inside the template you can maybe use:

ListenAddress <%= scope.lookupvar(@module_name + '::_local_addresses').join(' ') %>
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools


Asked: 2017-07-03 06:23:26 -0600

Seen: 275 times

Last updated: Jul 08 '17