Some work in progress environment support
This commit is contained in:
parent
1a6805d469
commit
16870d72d1
|
@ -1,54 +1,35 @@
|
||||||
# This Vagrantfile can be used to develop Vagrant. Note that VirtualBox
|
|
||||||
# doesn't run in VirtualBox so you can't actually _run_ Vagrant within
|
|
||||||
# the VM created by this Vagrantfile, but you can use it to develop the
|
|
||||||
# Ruby, run unit tests, etc.
|
|
||||||
|
|
||||||
Vagrant.configure("2") do |config|
|
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
||||||
config.vm.box = "hashicorp/precise64"
|
VAGRANTFILE_API_VERSION = "2"
|
||||||
|
|
||||||
["virtualbox", "vmware_fusion", "vmware_workstation"].each do |provider|
|
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||||
config.vm.provider provider do |v, override|
|
config.vm.box = "centos7"
|
||||||
v.memory = "1024"
|
|
||||||
|
config.vm.define :centos7 do |centos7|
|
||||||
|
config.vm.network "private_network", ip: "192.168.11.3"
|
||||||
|
config.vm.hostname = "centos7"
|
||||||
|
# config.vm.network "public_network"
|
||||||
|
# config.ssh.forward_agent = true
|
||||||
|
config.vm.synced_folder "../puppet", "/puppet"
|
||||||
|
|
||||||
|
config.vm.provider "virtualbox" do |vb|
|
||||||
|
vb.gui = false
|
||||||
|
# Use VBoxManage to customize the VM. For example to change memory:
|
||||||
|
vb.customize ["modifyvm", :id, "--memory", "2048"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
config.vm.provision "puppet" do |puppet|
|
||||||
|
puppet.environmentpath = "../puppet/environments"
|
||||||
|
puppet.environment = "testenv"
|
||||||
|
# puppet.manifests_path = "../puppet/manifests"
|
||||||
|
# puppet.manifest_file = "site.pp"
|
||||||
|
puppet.module_path = [ "../puppet/modules/public", "../puppet/modules/private" ]
|
||||||
|
# puppet.options = "--debug --verbose"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Deprecated method:
|
||||||
|
#puppet apply --debug --verbose --modulepath '/puppet/modules/private:/puppet/modules/public:/etc/puppet/modules'
|
||||||
|
#--manifestdir /tmp/vagrant-puppet-1/manifests --detailed-exitcodes /tmp/vagrant-puppet-1/manifests/site.pp
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
config.vm.provision "shell", inline: $shell
|
|
||||||
end
|
end
|
||||||
|
|
||||||
$shell = <<-CONTENTS
|
|
||||||
MARKER_FILE="/usr/local/etc/vagrant_provision_marker"
|
|
||||||
|
|
||||||
# Only provision once
|
|
||||||
if [ -f "${MARKER_FILE}" ]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Update apt
|
|
||||||
apt-get update
|
|
||||||
|
|
||||||
# Install basic dependencies
|
|
||||||
apt-get install -y build-essential bsdtar curl
|
|
||||||
|
|
||||||
# Install RVM
|
|
||||||
su -l -c 'curl -L https://get.rvm.io | bash -s stable' vagrant
|
|
||||||
|
|
||||||
# Add the vagrant user to the RVM group
|
|
||||||
#usermod -a -G rvm vagrant
|
|
||||||
|
|
||||||
# Install some Rubies
|
|
||||||
su -l -c 'rvm install 2.1.1' vagrant
|
|
||||||
su -l -c 'rvm --default use 2.1.1' vagrant
|
|
||||||
|
|
||||||
# Output the Ruby version (for sanity)
|
|
||||||
su -l -c 'ruby --version' vagrant
|
|
||||||
|
|
||||||
# Install Git
|
|
||||||
apt-get install -y git
|
|
||||||
|
|
||||||
# Automatically move into the shared folder, but only add the command
|
|
||||||
# if it's not already there.
|
|
||||||
grep -q 'cd /vagrant' /home/vagrant/.bash_profile || echo 'cd /vagrant' >> /home/vagrant/.bash_profile
|
|
||||||
|
|
||||||
# Touch the marker file so we don't do this again
|
|
||||||
touch ${MARKER_FILE}
|
|
||||||
CONTENTS
|
|
||||||
|
|
|
@ -10,6 +10,8 @@ module VagrantPlugins
|
||||||
attr_accessor :hiera_config_path
|
attr_accessor :hiera_config_path
|
||||||
attr_accessor :manifest_file
|
attr_accessor :manifest_file
|
||||||
attr_accessor :manifests_path
|
attr_accessor :manifests_path
|
||||||
|
attr_accessor :environment
|
||||||
|
attr_accessor :environmentpath
|
||||||
attr_accessor :module_path
|
attr_accessor :module_path
|
||||||
attr_accessor :options
|
attr_accessor :options
|
||||||
attr_accessor :synced_folder_type
|
attr_accessor :synced_folder_type
|
||||||
|
@ -22,6 +24,8 @@ module VagrantPlugins
|
||||||
@hiera_config_path = UNSET_VALUE
|
@hiera_config_path = UNSET_VALUE
|
||||||
@manifest_file = UNSET_VALUE
|
@manifest_file = UNSET_VALUE
|
||||||
@manifests_path = UNSET_VALUE
|
@manifests_path = UNSET_VALUE
|
||||||
|
@environment = UNSET_VALUE
|
||||||
|
@environmentpath = UNSET_VALUE
|
||||||
@module_path = UNSET_VALUE
|
@module_path = UNSET_VALUE
|
||||||
@options = []
|
@options = []
|
||||||
@facter = {}
|
@facter = {}
|
||||||
|
@ -45,24 +49,45 @@ module VagrantPlugins
|
||||||
def merge(other)
|
def merge(other)
|
||||||
super.tap do |result|
|
super.tap do |result|
|
||||||
result.facter = @facter.merge(other.facter)
|
result.facter = @facter.merge(other.facter)
|
||||||
|
result.environmentpath = @facter.merge(other.environmentpath)
|
||||||
|
result.environment = @facter.merge(other.environment)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def finalize!
|
def finalize!
|
||||||
super
|
super
|
||||||
|
|
||||||
if @manifests_path == UNSET_VALUE
|
if @environmentpath == UNSET_VALUE
|
||||||
@manifests_path = [:host, "manifests"]
|
if @manifests_path == UNSET_VALUE
|
||||||
end
|
if 1 #If puppet 3.4+
|
||||||
|
puts "Puppet 3.4+, manifests_path is unset and environmentpath is unset, presuming an environment"
|
||||||
|
@environmentpath = [:host, "environments"]
|
||||||
|
else
|
||||||
|
@manifests_path = [:host, "manifests"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if @manifests_path && !@manifests_path.is_a?(Array)
|
if @manifests_path && !@manifests_path.is_a?(Array)
|
||||||
@manifests_path = [:host, @manifests_path]
|
@manifests_path = [:host, @manifests_path]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if @environmentpath && !@environmentpath.is_a?(Array)
|
||||||
|
@environmentpath = [:host, @environmentpath]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@manifests_path[0] = @manifests_path[0].to_sym
|
|
||||||
|
|
||||||
@hiera_config_path = nil if @hiera_config_path == UNSET_VALUE
|
@hiera_config_path = nil if @hiera_config_path == UNSET_VALUE
|
||||||
@manifest_file = "default.pp" if @manifest_file == UNSET_VALUE
|
|
||||||
|
if @environmentpath == UNSET_VALUE
|
||||||
|
@manifests_path[0] = @manifests_path[0].to_sym
|
||||||
|
@environmentpath = nil
|
||||||
|
@manifest_file = "default.pp" if @manifest_file == UNSET_VALUE
|
||||||
|
else
|
||||||
|
@environmentpath[0] = @environmentpath[0].to_sym
|
||||||
|
@environment = "production" if @environment == UNSET_VALUE
|
||||||
|
@manifest_file = nil
|
||||||
|
end
|
||||||
|
|
||||||
@module_path = nil if @module_path == UNSET_VALUE
|
@module_path = nil if @module_path == UNSET_VALUE
|
||||||
@synced_folder_type = nil if @synced_folder_type == UNSET_VALUE
|
@synced_folder_type = nil if @synced_folder_type == UNSET_VALUE
|
||||||
@temp_dir = nil if @temp_dir == UNSET_VALUE
|
@temp_dir = nil if @temp_dir == UNSET_VALUE
|
||||||
|
@ -96,8 +121,13 @@ module VagrantPlugins
|
||||||
# Calculate the manifests and module paths based on env
|
# Calculate the manifests and module paths based on env
|
||||||
this_expanded_module_paths = expanded_module_paths(machine.env.root_path)
|
this_expanded_module_paths = expanded_module_paths(machine.env.root_path)
|
||||||
|
|
||||||
|
if environmentpath != UNSET_VALUE && manifests_path != UNSET_VALUE
|
||||||
|
errors << "You may not specify both environmentpath and manifests_path. Please specify environment and environmentpath only"
|
||||||
|
end
|
||||||
|
|
||||||
# Manifests path/file validation
|
# Manifests path/file validation
|
||||||
if manifests_path[0].to_sym == :host
|
puts "manifests_path is #{manifests_path}"
|
||||||
|
if manifests_path != UNSET_VALUE && manifests_path[0].to_sym == :host
|
||||||
expanded_path = Pathname.new(manifests_path[1]).
|
expanded_path = Pathname.new(manifests_path[1]).
|
||||||
expand_path(machine.env.root_path)
|
expand_path(machine.env.root_path)
|
||||||
if !expanded_path.directory?
|
if !expanded_path.directory?
|
||||||
|
@ -110,8 +140,29 @@ module VagrantPlugins
|
||||||
manifest: expanded_manifest_file.to_s)
|
manifest: expanded_manifest_file.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Environments path/file validation
|
||||||
|
if environmentpath != UNSET_VALUE && environmentpath[0].to_sym == :host
|
||||||
|
expanded_path = Pathname.new(environmentpath[1]).
|
||||||
|
expand_path(machine.env.root_path)
|
||||||
|
if !expanded_path.directory?
|
||||||
|
errors << I18n.t("vagrant.provisioners.puppet.environmentpath_missing",
|
||||||
|
path: expanded_path.to_s)
|
||||||
|
else
|
||||||
|
expanded_environment_file = expanded_path.join(environment)
|
||||||
|
if !expanded_environment_file.file? && !expanded_environment_file.directory?
|
||||||
|
errors << I18n.t("vagrant.provisioners.puppet.environment_missing",
|
||||||
|
environment: environment.to_s,
|
||||||
|
environmentpath: expanded_path.to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if environmentpath == UNSET_VALUE && manifests_path == UNSET_VALUE
|
||||||
|
errors << "Please specify either a Puppet environmentpath + environment (preferred) or manifests_path (deprecated)."
|
||||||
|
end
|
||||||
|
|
||||||
# Module paths validation
|
# Module paths validation
|
||||||
this_expanded_module_paths.each do |path|
|
this_expanded_module_paths.each do |path|
|
||||||
if !path.directory?
|
if !path.directory?
|
||||||
|
|
|
@ -18,7 +18,6 @@ module VagrantPlugins
|
||||||
# Calculate the paths we're going to use based on the environment
|
# Calculate the paths we're going to use based on the environment
|
||||||
root_path = @machine.env.root_path
|
root_path = @machine.env.root_path
|
||||||
@expanded_module_paths = @config.expanded_module_paths(root_path)
|
@expanded_module_paths = @config.expanded_module_paths(root_path)
|
||||||
@manifest_file = File.join(manifests_guest_path, @config.manifest_file)
|
|
||||||
|
|
||||||
# Setup the module paths
|
# Setup the module paths
|
||||||
@module_paths = []
|
@module_paths = []
|
||||||
|
@ -30,11 +29,23 @@ module VagrantPlugins
|
||||||
folder_opts[:type] = @config.synced_folder_type if @config.synced_folder_type
|
folder_opts[:type] = @config.synced_folder_type if @config.synced_folder_type
|
||||||
folder_opts[:owner] = "root" if !@config.synced_folder_type
|
folder_opts[:owner] = "root" if !@config.synced_folder_type
|
||||||
|
|
||||||
# Share the manifests directory with the guest
|
if @config.environmentpath.is_a?(Array)
|
||||||
if @config.manifests_path[0].to_sym == :host
|
# Share the environments directory with the guest
|
||||||
root_config.vm.synced_folder(
|
if @config.environmentpath[0].to_sym == :host
|
||||||
File.expand_path(@config.manifests_path[1], root_path),
|
root_config.vm.synced_folder(
|
||||||
manifests_guest_path, folder_opts)
|
File.expand_path(@config.environmentpath[1], root_path),
|
||||||
|
environments_guest_path, folder_opts)
|
||||||
|
end
|
||||||
|
parse_environment_metadata()
|
||||||
|
else
|
||||||
|
# Non-Environment mode
|
||||||
|
@manifest_file = File.join(manifests_guest_path, @config.manifest_file)
|
||||||
|
# Share the manifests directory with the guest
|
||||||
|
if @config.manifests_path[0].to_sym == :host
|
||||||
|
root_config.vm.synced_folder(
|
||||||
|
File.expand_path(@config.manifests_path[1], root_path),
|
||||||
|
manifests_guest_path, folder_opts)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Share the module paths
|
# Share the module paths
|
||||||
|
@ -43,6 +54,24 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# For convenience, add in any module_paths from the Puppet environment.cfg to the vagrant module_paths
|
||||||
|
# This is needed because puppet apply does not read environment metadata (as of v3.6)
|
||||||
|
def parse_environment_metadata
|
||||||
|
environment_conf = File.join(environments_guest_path, @config.environment, "environment.conf")
|
||||||
|
if @machine.communicate.test("test -e #{environment_conf}", sudo: true)
|
||||||
|
conf = @machine.communicate.sudo("cat #{environment_conf}") do | type, data|
|
||||||
|
if type == :stdout
|
||||||
|
#modulepath = $basemodulepath:modules/private:modules/public
|
||||||
|
puts "got line #{data}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
puts "Found an environment cfg at: #{environment_conf} - #{conf}"
|
||||||
|
else
|
||||||
|
puts "env cfg not found, looked for #{environment_conf}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def provision
|
def provision
|
||||||
# If the machine has a wait for reboot functionality, then
|
# If the machine has a wait for reboot functionality, then
|
||||||
# do that (primarily Windows)
|
# do that (primarily Windows)
|
||||||
|
@ -52,9 +81,12 @@ module VagrantPlugins
|
||||||
|
|
||||||
# Check that the shared folders are properly shared
|
# Check that the shared folders are properly shared
|
||||||
check = []
|
check = []
|
||||||
if @config.manifests_path[0] == :host
|
if @config.manifests_path.is_a?(Array) && @config.manifests_path[0] == :host
|
||||||
check << manifests_guest_path
|
check << manifests_guest_path
|
||||||
end
|
end
|
||||||
|
if @config.environmentpath.is_a?(Array) && @config.environmentpath[0] == :host
|
||||||
|
check << environments_guest_path
|
||||||
|
end
|
||||||
@module_paths.each do |host_path, guest_path|
|
@module_paths.each do |host_path, guest_path|
|
||||||
check << guest_path
|
check << guest_path
|
||||||
end
|
end
|
||||||
|
@ -92,6 +124,16 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def environments_guest_path
|
||||||
|
if config.environmentpath[0] == :host
|
||||||
|
# The path is on the host, so point to where it is shared
|
||||||
|
File.join(config.temp_dir, "environments")
|
||||||
|
else
|
||||||
|
# The path is on the VM, so just point directly to it
|
||||||
|
config.environmentpath[1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def verify_binary(binary)
|
def verify_binary(binary)
|
||||||
@machine.communicate.sudo(
|
@machine.communicate.sudo(
|
||||||
"which #{binary}",
|
"which #{binary}",
|
||||||
|
@ -125,10 +167,18 @@ module VagrantPlugins
|
||||||
options << "--color=false"
|
options << "--color=false"
|
||||||
end
|
end
|
||||||
|
|
||||||
options << "--manifestdir #{manifests_guest_path}"
|
|
||||||
options << "--detailed-exitcodes"
|
options << "--detailed-exitcodes"
|
||||||
options << @manifest_file
|
|
||||||
|
if !config.environmentpath.empty?
|
||||||
|
options << "#{environments_guest_path}/#{@config.environment}/manifests"
|
||||||
|
options << "--environment #{@config.environment}"
|
||||||
|
else
|
||||||
|
options << "--manifestdir #{manifests_guest_path}"
|
||||||
|
options << @manifest_file
|
||||||
|
end
|
||||||
options = options.join(" ")
|
options = options.join(" ")
|
||||||
|
|
||||||
|
@machine.ui.info("Running ye puppet apply with options #{options}")
|
||||||
|
|
||||||
# Build up the custom facts if we have any
|
# Build up the custom facts if we have any
|
||||||
facter = ""
|
facter = ""
|
||||||
|
@ -155,9 +205,15 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@machine.ui.info(I18n.t(
|
if !config.environmentpath.empty?
|
||||||
"vagrant.provisioners.puppet.running_puppet",
|
@machine.ui.info(I18n.t(
|
||||||
manifest: config.manifest_file))
|
"vagrant.provisioners.puppet.running_puppet_env",
|
||||||
|
environment: config.environment))
|
||||||
|
else
|
||||||
|
@machine.ui.info(I18n.t(
|
||||||
|
"vagrant.provisioners.puppet.running_puppet",
|
||||||
|
manifest: config.manifest_file))
|
||||||
|
end
|
||||||
|
|
||||||
opts = {
|
opts = {
|
||||||
elevated: true,
|
elevated: true,
|
||||||
|
|
|
@ -1733,12 +1733,23 @@ en:
|
||||||
installed on this guest. Puppet provisioning can not continue without
|
installed on this guest. Puppet provisioning can not continue without
|
||||||
Puppet properly installed.
|
Puppet properly installed.
|
||||||
running_puppet: "Running Puppet with %{manifest}..."
|
running_puppet: "Running Puppet with %{manifest}..."
|
||||||
|
running_puppet_env: "Running Puppet with environment %{environment}..."
|
||||||
manifest_missing: |-
|
manifest_missing: |-
|
||||||
The configured Puppet manifest is missing. Please specify a path to an
|
The configured Puppet manifest is missing. Please specify a path to an
|
||||||
existing manifest:
|
existing manifest:
|
||||||
|
|
||||||
%{manifest}
|
%{manifest}
|
||||||
|
environment_missing: |-
|
||||||
|
The configured Puppet environment folder '%{environment}' was not found in the
|
||||||
|
specified environmentpath %{environmentpath}.
|
||||||
|
Please specify a path to an existing Puppet directory environment.
|
||||||
manifests_path_missing: "The manifests path specified for Puppet does not exist: %{path}"
|
manifests_path_missing: "The manifests path specified for Puppet does not exist: %{path}"
|
||||||
|
manifest_missing: |-
|
||||||
|
The configured Puppet envrionment is missing. Please specify a path to an
|
||||||
|
existing envrionment file:
|
||||||
|
|
||||||
|
%{environment}
|
||||||
|
manifests_path_missing: "The environment path specified for Puppet does not exist: %{path}"
|
||||||
missing_shared_folders: |-
|
missing_shared_folders: |-
|
||||||
Shared folders that Puppet requires are missing on the virtual machine.
|
Shared folders that Puppet requires are missing on the virtual machine.
|
||||||
This is usually due to configuration changing after already booting the
|
This is usually due to configuration changing after already booting the
|
||||||
|
|
|
@ -15,7 +15,8 @@ Gem::Specification.new do |s|
|
||||||
s.required_rubygems_version = ">= 1.3.6"
|
s.required_rubygems_version = ">= 1.3.6"
|
||||||
s.rubyforge_project = "vagrant"
|
s.rubyforge_project = "vagrant"
|
||||||
|
|
||||||
s.add_dependency "bundler", ">= 1.5.2", "< 1.7.0"
|
s.add_dependency "bundler", ">= 1.5.2"
|
||||||
|
#, "< 1.7.0"
|
||||||
s.add_dependency "childprocess", "~> 0.5.0"
|
s.add_dependency "childprocess", "~> 0.5.0"
|
||||||
s.add_dependency "erubis", "~> 2.7.0"
|
s.add_dependency "erubis", "~> 2.7.0"
|
||||||
s.add_dependency "i18n", "~> 0.6.0"
|
s.add_dependency "i18n", "~> 0.6.0"
|
||||||
|
|
Loading…
Reference in New Issue