module Chef::Sugar::Vagrant

Public Instance Methods

vagrant?(node) click to toggle source

Determine if the current node is running in vagrant mode.

@param [Chef::Node] node

@return [Boolean]

true if the machine is currently running vagrant, false
otherwise
# File lib/chef/sugar/vagrant.rb, line 31
def vagrant?(node)
  vagrant_key?(node) || vagrant_domain?(node) || vagrant_user?(node)
end

Private Instance Methods

vagrant_domain?(node) click to toggle source

Check if “vagrantup.com” is included in the node's domain. Technically, this would make Chef Sugar falsely detect vagrant? on any of Hashicorp's servers. But if that edge case becomes a serious problem, @mitchellh has my phone number.

@param (see vagrant?) @return (see vagrant?)

# File lib/chef/sugar/vagrant.rb, line 57
def vagrant_domain?(node)
  node.key?('domain') && !node['domain'].nil? && node['domain'].include?('vagrantup.com')
end
vagrant_key?(node) click to toggle source

Check if the vagrant key exists on the node object. This key is no longer populated by vagrant, but it is kept around for legacy purposes.

@param (see vagrant?) @return (see vagrant?)

# File lib/chef/sugar/vagrant.rb, line 44
def vagrant_key?(node)
  node.key?('vagrant')
end
vagrant_user?(node) click to toggle source

Check if the system contains a vagrant user.

@param (see vagrant?) @return (see vagrant?)

# File lib/chef/sugar/vagrant.rb, line 67
def vagrant_user?(node)
  node.key?('etc') && node['etc'].key?('passwd') && node['etc']['passwd'].key?('vagrant')
end