Last active
August 29, 2015 14:06
-
-
Save dragolabs/2676c70bd2659b0a8f2f to your computer and use it in GitHub Desktop.
Dumb ohai7 plugin show all IP addresses of the node exclude localhost.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Author:: Vitaly Shishlyannikov (<[email protected]>) | |
# Copyright:: Copyright (c) 2014 | |
# License:: Apache License, Version 2.0 | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# Dumb ohai7 plugin show all IP addresses of the node exclude localhost. | |
Ohai.plugin(:Allip) do | |
provides "all_ip" | |
depends "network/interfaces" | |
collect_data do | |
ips = network["interfaces"].keys.map { |iface_name| network["interfaces"][iface_name]["addresses"].keys} | |
result = [] | |
ips.each do |ip| | |
if ip.kind_of?(Array) then | |
ip.each do |ip_deep| | |
result << ip_deep if (ip_deep !~ /^127|::1/ ) | |
end | |
else | |
result << ip if (ip !~ /^127|::1/) | |
end | |
end | |
all_ip result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment