Auto-detect policy server IP for CFEngine
This commit is contained in:
parent
9b9ed2d2aa
commit
66ff86fda5
|
@ -139,6 +139,10 @@ module Vagrant
|
|||
error_key(:cfengine_bootstrap_failed)
|
||||
end
|
||||
|
||||
class CFEngineCantAutodetectIP < VagrantError
|
||||
error_key(:cfengine_cant_autodetect_ip)
|
||||
end
|
||||
|
||||
class CFEngineInstallFailed < VagrantError
|
||||
error_key(:cfengine_install_failed)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
module VagrantPlugins
|
||||
module GuestLinux
|
||||
module Cap
|
||||
class ReadIPAddress
|
||||
def self.read_ip_address(machine)
|
||||
command = "ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'"
|
||||
result = ""
|
||||
machine.communicate.execute(command) do |type, data|
|
||||
result << data if type == :stdout
|
||||
end
|
||||
|
||||
result.chomp
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -30,6 +30,11 @@ module VagrantPlugins
|
|||
require_relative "cap/mount_virtualbox_shared_folder"
|
||||
Cap::MountVirtualBoxSharedFolder
|
||||
end
|
||||
|
||||
guest_capability("linux", "read_ip_address") do
|
||||
require_relative "cap/read_ip_address"
|
||||
Cap::ReadIPAddress
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -90,7 +90,9 @@ module VagrantPlugins
|
|||
errors << I18n.t("vagrant.cfengine_config.invalid_mode") if !valid_modes.include?(@mode)
|
||||
|
||||
if @mode == :bootstrap
|
||||
errors << I18n.t("vagrant.cfengine_config.policy_server_address") if !@policy_server_address
|
||||
if !@policy_server_address && !@am_policy_hub
|
||||
errors << I18n.t("vagrant.cfengine_config.policy_server_address")
|
||||
end
|
||||
end
|
||||
|
||||
if @classes && !@classes.is_a?(Array)
|
||||
|
|
|
@ -79,6 +79,11 @@ module VagrantPlugins
|
|||
|
||||
# Needs bootstrap, let's determine the parameters
|
||||
policy_server_address = @config.policy_server_address
|
||||
if !policy_server_address
|
||||
policy_server_address = @machine.guest.capability(:read_ip_address)
|
||||
raise Vagrant::Errors::CFEngineCantAutodetectIP if !policy_server_address
|
||||
@machine.ui.info(I18n.t("vagrant.cfengine_detected_ip", address: policy_server_address))
|
||||
end
|
||||
|
||||
@machine.ui.info(I18n.t("vagrant.cfengine_bootstrapping",
|
||||
policy_server: policy_server_address))
|
||||
|
|
|
@ -4,10 +4,17 @@ en:
|
|||
Bootstrapping CFEngine with policy server: %{policy_server}...
|
||||
cfengine_bootstrapping_policy_hub: |-
|
||||
Performing additional bootstrap for policy hubs...
|
||||
cfengine_cant_autodetect_ip: |-
|
||||
Vagrant was unable to automatically detect the IP address of the
|
||||
running machine to use as the policy server address. Please specify
|
||||
the policy server address manually, or verify that the networks are
|
||||
configured properly internally.
|
||||
cfengine_cant_detect: |-
|
||||
Vagrant doesn't support detecting whether CFEngine is installed
|
||||
for the guest OS running in the machine. Vagrant will assume it is
|
||||
installed and attempt to continue.
|
||||
cfengine_detected_ip: |-
|
||||
Detected policy server IP address: %{address}...
|
||||
cfengine_installing: |-
|
||||
Installing CFEngine onto machine...
|
||||
cfengine_installing_files_path: |-
|
||||
|
|
Loading…
Reference in New Issue