Skip to content

Instantly share code, notes, and snippets.

@scopenco
Created August 11, 2017 11:24
Show Gist options
  • Select an option

  • Save scopenco/3d5786c2209b0f693b1fcdd45e463ebf to your computer and use it in GitHub Desktop.

Select an option

Save scopenco/3d5786c2209b0f693b1fcdd45e463ebf to your computer and use it in GitHub Desktop.

Revisions

  1. scopenco created this gist Aug 11, 2017.
    35 changes: 35 additions & 0 deletions ohai-vbox-ipaddress-plugin.rb.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    #
    # Author:: Andrei Skopenko (<andrei@skopenko.net>)
    #
    # Copyright 2017, Andrei Skopenko
    #
    # 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.
    #

    Ohai.plugin(:Vboxipaddress) do
    provides "ipaddress"
    depends "ipaddress", "network/interfaces", "virtualization/system", "etc/passwd"

    collect_data(:default) do
    # linux
    if virtualization["system"] == "vbox" && etc["passwd"].any? { |k,v| k == "vagrant"}
    interface_key = network["interfaces"].keys.last
    network["interfaces"][interface_key]['addresses'].each do |ip, params|
    ipaddress ip if params['family'] == ('inet')
    end
    # windows
    elsif kernel['cs_info'] && kernel['cs_info']['model'] == 'VirtualBox'
    ipaddress network["interfaces"][interface_key]['configuration']['ip_address'][0]
    end
    end
    end