vagrant-invade 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6d05d703e83eeb6fc6d8ffb8e0de3c50988d58f
4
- data.tar.gz: 8dafe62da9c4bc56d8fb82d01062ccec910924f6
3
+ metadata.gz: '0977b18727d49b4db925ac88c804d93ebebde0cd'
4
+ data.tar.gz: 6a49503d802b6121f0158cdd67c135ab2041dc0e
5
5
  SHA512:
6
- metadata.gz: 0ca932f0f09a78d05fbe3f0fc7de6f5b6da85d26c49b6abf8c35d34af84e9ad5880a980de74d600ac0961b414664aca98107f9ef677043bc5a72b424fe5fe088
7
- data.tar.gz: 21beb6a37e3e975f10185247c05e7171a9388c06954de003145d5357262df9e74ced320f5fa745db7002683bbfcfe46856aed0c0e49d6b41e151ae7986787ed8
6
+ metadata.gz: cdeaed579dc3a84480e4b9273944c79bb9c5be4788253fa0206d3c0c734b872358639ef4e3a7fd5bc3cd87df4d10033ac786f6b720baf2646dfdbb3e2d31684f
7
+ data.tar.gz: 3f003a531ce20fae20f4cc29911975558d657146ba65ceb94a7cf29dcd774502d9143f38e89c20b23868ad48017a343e52653c736bc73bfc428dc2a484e28d3f
data/.gitignore CHANGED
@@ -1,4 +1,8 @@
1
+ !invade-default.yml
1
2
  invade.yml
3
+ invade.yaml
4
+ invade-*.yml
5
+ invade-*.yaml
2
6
  Vagrantfile
3
7
  !Vagrantfile/
4
8
  !vagrantfile.rb
data/README.md CHANGED
@@ -12,7 +12,7 @@ Simply run `vagrant plugin install vagrant-invade`
12
12
  To install a certain version use the `-v 'VERSION'` option.
13
13
 
14
14
  ## Commands
15
- There are new commands you can use to init, validate and build your Vagrantfile.
15
+ There are new commands you can use to init, validate and build a Vagrantfile.
16
16
 
17
17
  ### Init
18
18
  `vagrant invade init` creates the default **invade.yml** configuration file for you.
@@ -33,11 +33,12 @@ There are new commands you can use to init, validate and build your Vagrantfile.
33
33
  * VirtualBox
34
34
  * VMWare
35
35
  * Provision
36
- * shell
37
- * inline
36
+ * ansible
37
+ * ansible_local
38
38
  * puppet-agent
39
39
  * puppet-apply
40
40
  * salt
41
+ * shell
41
42
  * Synced Folder
42
43
  * VB
43
44
  * NFS (use *vagrant-winnfsd* plugin to support Windows)
@@ -14,20 +14,28 @@ module VagrantPlugins
14
14
  def self.get_invade_config
15
15
 
16
16
  #Loading Invade configuration settings from file
17
- invade_config_file = Dir.pwd + '/invade.yml'
17
+ invade_config_file = Dir.glob(Dir.pwd + "/invade.{yml,yaml}")
18
+ invade_config = Hash.new
18
19
 
19
- if File.exists?(invade_config_file)
20
- begin
21
- return YAML.load_file(invade_config_file)
22
- rescue SyntaxError => e
23
- @logger.error e
24
- fail e
25
- end
26
- else
27
- @config_values = nil
20
+ # If sinlge file configuration for invade exists - use it
21
+ if invade_config_file.any?
22
+ invade_config = YAML.load_file(invade_config_file[0])
28
23
  end
24
+
25
+ # Creates empty machine hash if it not exists
26
+ if invade_config['machine'].nil?
27
+ invade_config['machine'] = Hash.new
28
+ end
29
+
30
+ # Iterate over each machine definition in ./invade/ folder and deep merge it
31
+ Dir.glob("#{Dir.pwd}/invade-*.{yml,yaml}") do |config|
32
+ invade_config.deep_merge!(YAML.load_file(config))
33
+ end
34
+
35
+ # Clean hash from empty/nil values recursively
36
+ invade_config = invade_config.deep_compact(exclude_blanks: true)
29
37
 
30
- @config_values
38
+ invade_config
31
39
  end
32
40
  end
33
41
  end
@@ -28,12 +28,21 @@ module VagrantPlugins
28
28
  end
29
29
  end
30
30
 
31
+ def self.check
32
+ Vagrant::Action::Builder.new.tap do |builder|
33
+ builder.use Config
34
+ builder.use Process
35
+ builder.use Check
36
+ end
37
+ end
38
+
31
39
  # The autoload farm
32
40
  action_root = Pathname.new(File.expand_path('../action', __FILE__))
33
41
  autoload :Init, action_root.join('init')
34
42
  autoload :Config, action_root.join('config')
35
43
  autoload :Process, action_root.join('process')
36
44
  autoload :Create, action_root.join('create')
45
+ autoload :Check, action_root.join('check')
37
46
 
38
47
  end
39
48
  end
@@ -0,0 +1,48 @@
1
+ module VagrantPlugins
2
+ module Invade
3
+ module Action
4
+
5
+ include Vagrant::Action::Builtin
6
+
7
+ class Check
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ @env = env
12
+ @ui = env[:ui]
13
+ @logger = Log4r::Logger.new('vagrant::invade::action::check')
14
+
15
+ ENV['VAGRANT_VAGRANTFILE'] ? @vagrantfile_name = ENV['VAGRANT_VAGRANTFILE'] : @vagrantfile_name = 'Vagrantfile'
16
+ @root_path = Dir.pwd
17
+ end
18
+
19
+ def call(env)
20
+
21
+ data = @env[:invade]['vagrantfile']
22
+
23
+ checksum_helper = Helper::Checksum.new data
24
+ vagrantfile_path = "#{@root_path}/#{@vagrantfile_name}"
25
+ md5_current = checksum_helper.get_checksum_of_file(vagrantfile_path)
26
+ md5_generated = checksum_helper.get_checksum_of_data
27
+
28
+ if checksum_helper.check
29
+ @ui.success "[Invade][CHECK] NO CHANGES FOUND"
30
+ @ui.success "----------------------------------------------------------"
31
+ @ui.success "[Invade][CHECK] Current : '#{md5_current}'"
32
+ @ui.success "[Invade][CHECK] Generated : '#{md5_generated}'"
33
+ @ui.success "[Invade][CHECK] No changes found."
34
+ else
35
+ @ui.warn "[Invade][CHECK] CONFIGURATION FILE UPDATED"
36
+ @ui.warn "-------------------------------------------------------------"
37
+ @ui.warn "[Invade][CHECK] Current : '#{md5_current}'"
38
+ @ui.warn "[Invade][CHECK] Generated : '#{md5_generated}'"
39
+ @ui.warn '[Invade][CHECK] Configuration file updated - free to rebuild.'
40
+ end
41
+
42
+ @app.call(env)
43
+ end
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -19,13 +19,13 @@ module VagrantPlugins
19
19
  def call(env)
20
20
 
21
21
  config_file_path = "#{@dir}/invade.yml"
22
- # template_file_path = "#{config_file_path}.dist"
23
- # default_config_file_path = "#{File.expand_path('../../../../', __FILE__)}/invade.yml.dist"
24
22
 
25
23
  # Returns with invade in environment if Invade Configuration file already exists
26
24
  if File.exist?(config_file_path)
27
25
  @logger.debug 'Config file found. Proceed.'
28
- @env[:ui].info "[Invade] Using Plugin vagrant-invade-#{VERSION} to setup Vagrant!"
26
+ @env[:ui].info "[Invade] Using Plugin vagrant-invade-#{VERSION} to build a Vagrantfile."
27
+ @env[:ui].info '-----------------------------------------------------------------------'
28
+ @env[:ui].info ''
29
29
 
30
30
  # Add invade configuration as global environment variable since we know configuration file exists
31
31
  env[:invade] = Invade.get_invade_config
@@ -33,46 +33,13 @@ module VagrantPlugins
33
33
  raise 'Something went wrong. Configuration file could not be loaded.'
34
34
  end
35
35
  else
36
- @env[:ui].info "[Invade] 'invade.yml' not exists. You forgot a 'vagrant invade init'?"
36
+ @env[:ui].info "[Invade] 'invade.yml' not exists. You forgot to 'vagrant invade init'?"
37
37
  exit
38
-
39
- # # Try to copy template path from vagrant repository of project.
40
- # begin
41
- # FileUtils.cp(template_file_path, config_file_path)
42
- # @logger.debug 'Config file could not be found. Copied template file.'
43
- # @env[:ui].debug '[Invade] Configuration file could not be found.'
44
- # @env[:ui].warn '[Invade] Copying template configuration...'
45
- # @env[:ui].warn "\tFrom: \"#{template_file_path}\""
46
- # @env[:ui].warn "\tTo: \"#{config_file_path}\""
47
- # sleep 2
48
- # @env[:ui].warn '[Invade] Restarting vagrant...'
49
- # sleep 3
50
- # if !Vagrant.in_installer? && !Vagrant.very_quiet?
51
- # Kernel.exec('bundle exec vagrant up') if @env[:invade_command]
52
- # else
53
- # Kernel.exec('vagrant up') if @env[:invade_command]
54
- # end
55
- # rescue
56
- # # If not found default invade configuration file will be copied.
57
- # FileUtils.cp(default_config_file_path, config_file_path)
58
- # @logger.info 'Template file could not be found. Copied default invade configuration file.'
59
- # @env[:ui].warn '[Invade] Template file could not be found.'
60
- # @env[:ui].warn '[Invade] Copying default configuration...'
61
- # @env[:ui].warn "\tFrom: \"#{template_file_path}\""
62
- # @env[:ui].warn "\tTo: \"#{config_file_path}\""
63
- # sleep 2
64
- # @env[:ui].warn '[Invade] Restarting vagrant...'
65
- # sleep 3
66
- # if !Vagrant.in_installer? && !Vagrant.very_quiet?
67
- # Kernel.exec('bundle exec vagrant up') if @env[:invade_command]
68
- # else
69
- # Kernel.exec('vagrant up') if @env[:invade_command]
70
- # end
71
- # end
72
38
  end
73
39
 
74
40
  @app.call(env)
75
41
  end
42
+
76
43
  end
77
44
 
78
45
  end
@@ -20,10 +20,10 @@ module VagrantPlugins
20
20
 
21
21
  data = @env[:invade]['vagrantfile']
22
22
 
23
- checksum_helper = Helper::Checksum.new @env
23
+ checksum_helper = Helper::Checksum.new data
24
24
  vagrantfile_path = "#{@root_path}/#{@vagrantfile_name}"
25
25
  md5_current = checksum_helper.get_checksum_of_file(vagrantfile_path)
26
- md5_generated = checksum_helper.get_checksum_of_data(data)
26
+ md5_generated = checksum_helper.get_checksum_of_data
27
27
 
28
28
  # Write new Vagrantfile if checksum is not equal
29
29
  if !checksum_helper.check
@@ -46,18 +46,23 @@ module VagrantPlugins
46
46
  if invade_template_exists
47
47
  template_file_path = "#{@dir}/invade.yml.dist"
48
48
  FileUtils.cp(template_file_path, invade_config_file)
49
- @env[:ui].success "[Invade] Project template file '#{template_file_path}' was found!"
49
+ @env[:ui].success "[Invade] Using local template file '#{template_file_path}'."
50
50
  elsif invade_user_customized_config_exists && !invade_template_exists
51
51
  FileUtils.cp(File.expand_path('~/.invade/invade.yml.dist'), invade_config_file)
52
- @env[:ui].success "[Invade] User customized template file '~/.invade/invade.yml.dist' was found!"
52
+ @env[:ui].success "[Invade] Using global template file '~/.invade/invade.yml.dist'."
53
53
  else
54
- plugin_root_path = File.expand_path('../../../../', __FILE__)
55
- default_invade_config_file = plugin_root_path + '/invade.yml.dist'
54
+ plugin_root_path = File.expand_path('../../../..', __FILE__)
55
+ default_invade_config_file = plugin_root_path + '/invade-default.yml'
56
+ template_file_path = "#{@dir}/invade.yml.dist"
56
57
  FileUtils.cp(default_invade_config_file, invade_config_file)
57
- @env[:ui].warn '[Invade] Project template file or customized user configuration file NOT found!'
58
+ @env[:ui].warn '[Invade] Global user template file \'~/.invade/invade.yml.dist\' not found.'
59
+ @env[:ui].warn "[Invade] Local template file './invade.yml.dist' not found."
60
+ @env[:ui].warn '[Invade] ------------------------------------------------------------------'
61
+ @env[:ui].warn "[Invade] Save a template file to it's location to use it as default."
58
62
  end
59
63
 
60
- @env[:ui].success '[Invade] \'invade.yml\' created successfully. Please make your changes.'
64
+ @env[:ui].success ""
65
+ @env[:ui].success '[Invade] Default \'invade.yml\' created successfully. Please make your changes.'
61
66
  end
62
67
  end
63
68
 
@@ -18,6 +18,7 @@ module VagrantPlugins
18
18
  @invade_vagrantfile = Hash.new
19
19
 
20
20
  @generate = @env[:invade_generate]
21
+ @build_quiet = @env[:invade_build_quiet]
21
22
  @quiet = @env[:invade_validate_quiet]
22
23
 
23
24
  @logger = Log4r::Logger.new('vagrant::invade::action::validate')
@@ -27,11 +28,14 @@ module VagrantPlugins
27
28
 
28
29
  config = env[:invade]
29
30
 
30
- # Remove empty Hashes
31
- config = config.compact(config)
31
+ # If config data is not a hash, something went totally wrong or it's not correct YAML
32
+ # This should never happen - but better to stop the progress here.
33
+ if !config.is_a?(Hash)
34
+ raise "Something went wrong parsing your configuration file. Is your YAML in a correct format?"
35
+ end
32
36
 
33
37
  config.each do |config_key, config_data|
34
- if config_key == 'machines'
38
+ if config_key == 'machine'
35
39
  process_machines(config_data)
36
40
  else
37
41
  process_vagrant_part(config_key, config_data)
@@ -43,26 +47,27 @@ module VagrantPlugins
43
47
  generator_type: Invade::Generator::Type::VAGRANTFILE
44
48
  ) if @generate
45
49
 
46
- @env[:invade].delete('machines')
50
+ @env[:invade].delete('machine')
47
51
 
48
52
  @app.call(env)
49
53
  end
50
54
 
51
55
  private
52
56
 
53
- def process_machines(machines)
54
-
57
+ def process_machines(machine)
58
+
55
59
  # Iterate over machine configurations
56
- machines.each_with_index do |(machine, machine_data), _|
60
+ machine.each_with_index do |(machine, machine_data), _|
57
61
  process_machine(machine, machine_data)
58
62
  end
59
63
 
60
- @invade_vagrantfile['machines'] = @invade_machine
61
- @env[:ui].success "\n[Invade]: Processed #{machines.count} machine(s)."
64
+ @invade_vagrantfile['machine'] = @invade_machine
65
+ @env[:ui].success "\n[Invade]: Processed #{machine.count} machine(s)." unless @build_quiet
62
66
 
63
67
  end
64
68
 
65
69
  def process_machine(machine_name, machine_data)
70
+
66
71
  # Iterate over each machine part configuration
67
72
  machine_data.each do |machine_part_name, machine_part_data|
68
73
  @env[:ui].info("\n[Invade][Machine: #{machine_name.upcase}]: Validating #{machine_part_name.upcase} part...") unless @quiet
@@ -82,6 +87,7 @@ module VagrantPlugins
82
87
  end
83
88
 
84
89
  def process_machine_part(machine, machine_part_name, machine_part_data)
90
+
85
91
  validated_data = validate('Machine', machine_part_name, machine_part_data, machine_part_data.depth)
86
92
  @invade_machine_part[machine_part_name] = generate(
87
93
  machine_name: machine,
@@ -0,0 +1,31 @@
1
+ require 'optparse'
2
+ require_relative 'base'
3
+
4
+ module VagrantPlugins
5
+ module Invade
6
+ module Command
7
+ class Check < Base
8
+ def execute
9
+ options = {}
10
+ opts = OptionParser.new do |o|
11
+ o.banner = 'Usage: vagrant invade check [-h]'
12
+ end
13
+
14
+ # Parse the options
15
+ argv = parse_options(opts)
16
+ return unless argv
17
+
18
+ # Validates InVaDE configuration
19
+ action(Action.check, {
20
+ :invade_generate => true,
21
+ :invade_validate_quiet => true,
22
+ :invade_build_quiet => true
23
+ })
24
+
25
+ # Success, exit status 0
26
+ 0
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -27,10 +27,16 @@ module VagrantPlugins
27
27
  end
28
28
 
29
29
  # BUILD COMMAND ("vagrant invade build")
30
- @subcommands.register(:build) do
30
+ @subcommands.register(:build) do
31
31
  require_relative 'build'
32
32
  Build
33
33
  end
34
+
35
+ # CHECK COMMAND ("vagrant invade check")
36
+ @subcommands.register(:check) do
37
+ require_relative 'check'
38
+ Check
39
+ end
34
40
  end
35
41
 
36
42
  def execute
@@ -1,3 +1,18 @@
1
+ class Object
2
+
3
+ def present?
4
+ !blank?
5
+ end
6
+
7
+ def presence
8
+ self if present?
9
+ end
10
+
11
+ def blank?
12
+ respond_to?(:empty?) ? !!empty? : !self
13
+ end
14
+ end
15
+
1
16
  class Hash
2
17
  def depth
3
18
  a = self.to_a
@@ -8,14 +23,46 @@ class Hash
8
23
  d
9
24
  end
10
25
 
11
- def compact(opts={})
26
+ def compact
27
+ self.select { |_, value| !value.nil? }
28
+ end
29
+
30
+ def compact!
31
+ self.reject! { |_, value| value.nil? }
32
+ end
33
+
34
+ def deep_compact(options = {})
12
35
  inject({}) do |new_hash, (k,v)|
13
- if !v.nil?
14
- new_hash[k] = opts[:recurse] && v.class == Hash ? v.compact(opts) : v
36
+ result = options[:exclude_blank] ? v.blank? : v.nil?
37
+ if !result
38
+ new_value = v.is_a?(Hash) ? v.deep_compact(options).presence : v
39
+ new_hash[k] = new_value if new_value
15
40
  end
16
41
  new_hash
17
42
  end
18
43
  end
44
+
45
+ def deep_merge(other_hash, &block)
46
+ dup.deep_merge!(other_hash, &block)
47
+ end
48
+
49
+ def deep_merge!(other_hash, &block)
50
+ other_hash.each_pair do |current_key, other_value|
51
+ this_value = self[current_key]
52
+
53
+ self[current_key] = if this_value.is_a?(Hash) && other_value.is_a?(Hash)
54
+ this_value.deep_merge(other_value, &block)
55
+ else
56
+ if block_given? && key?(current_key)
57
+ block.call(current_key, this_value, other_value)
58
+ else
59
+ other_value
60
+ end
61
+ end
62
+ end
63
+
64
+ self
65
+ end
19
66
  end
20
67
 
21
68
  class Array
@@ -4,13 +4,12 @@ module VagrantPlugins
4
4
 
5
5
  class Checksum
6
6
 
7
- attr_accessor :env, :root_path, :vagrantfile, :data
7
+ attr_accessor :data, :root_path, :vagrantfile
8
8
 
9
- def initialize(env)
10
- @env = env
9
+ def initialize(data)
10
+ @data = data
11
11
  @root_path = Dir.pwd
12
12
  @vagrantfile = ENV['VAGRANT_VAGRANTFILE'] ? vagrantfile_name = ENV['VAGRANT_VAGRANTFILE'] : vagrantfile_name = "Vagrantfile"
13
- @data = env[:invade]['vagrantfile']
14
13
  end
15
14
 
16
15
  # Compare Vagrantfile <=> invade.yml with MD5 checksum
@@ -27,7 +26,7 @@ module VagrantPlugins
27
26
  true
28
27
  end
29
28
 
30
- def get_checksum_of_data(data)
29
+ def get_checksum_of_data
31
30
 
32
31
  begin
33
32
  checksum = Digest::MD5.hexdigest(@data)
@@ -0,0 +1,49 @@
1
+ module VagrantPlugins
2
+ module Invade
3
+ module InvadeModule
4
+ module Ansible
5
+
6
+ class Ansible < InvadeModule
7
+
8
+ attr_reader :result
9
+ attr_accessor :machine_name, :ansible_data
10
+
11
+ def initialize(machine_name, ansible_data, result: nil)
12
+ @machine_name = machine_name
13
+ @ansible_data = ansible_data
14
+ @result = result
15
+ end
16
+
17
+ def build
18
+ b = binding
19
+
20
+ begin
21
+
22
+ # Get machine name
23
+ machine_name = @machine_name
24
+
25
+ # Values for ansible provisioner section
26
+ playbook = @ansible_data['playbook']
27
+ groups = @ansible_data['groups']
28
+ limit = @ansible_data['limit']
29
+ inventory_path = @ansible_data['inventory_path']
30
+ ask_sudo_pass = @ansible_data['ask_sudo_pass']
31
+ ask_vault_pass = @ansible_data['ask_vault_pass']
32
+ force_remote_user = @ansible_data['force_remote_user']
33
+ host_key_checking = @ansible_data['host_key_checking']
34
+ host_vars = @ansible_data['host_vars']
35
+ raw_ssh_args = @ansible_data['raw_ssh_args']
36
+ raw_arguments = @ansible_data['raw_arguments']
37
+
38
+ eruby = Erubis::Eruby.new(File.read(self.get_template_path(__FILE__)))
39
+ @result = eruby.result b
40
+ rescue TypeError, SyntaxError, SystemCallError => e
41
+ raise(e)
42
+ end
43
+ end
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,33 @@
1
+ playbook:
2
+ type: String
3
+ default: nil
4
+ groups:
5
+ type: Hash
6
+ default: nil
7
+ limit:
8
+ type: String
9
+ default: nil
10
+ inventory_path:
11
+ type: String
12
+ default: nil
13
+ ask_sudo_pass:
14
+ type: Boolean
15
+ default: nil
16
+ ask_vault_pass:
17
+ type: Boolean
18
+ default: nil
19
+ force_remote_user:
20
+ type: Boolean
21
+ default: nil
22
+ host_key_checking:
23
+ type: Boolean
24
+ default: nil
25
+ host_vars:
26
+ type: Hash
27
+ default: nil
28
+ raw_ssh_args:
29
+ type: Array
30
+ default: nil
31
+ raw_arguments:
32
+ type: Array
33
+ default: nil
@@ -0,0 +1,36 @@
1
+
2
+ <%= machine_name %>.vm.provision "ansible" do |ansible|
3
+ <% unless playbook.nil? %>
4
+ ansible.playbook = '<%= playbook %>'
5
+ <% end %>
6
+ <% unless groups.nil? %>
7
+ ansible.groups = '<%= groups %>'
8
+ <% end %>
9
+ <% unless limit.nil? %>
10
+ ansible.limit = '<%= limit %>'
11
+ <% end %>
12
+ <% unless inventory_path.nil? %>
13
+ ansible.inventory_path = '<%= inventory_path %>'
14
+ <% end %>
15
+ <% unless ask_sudo_pass.nil? %>
16
+ ansible.ask_sudo_pass = <%= ask_sudo_pass %>
17
+ <% end %>
18
+ <% unless ask_vault_pass.nil? %>
19
+ ansible.ask_vault_pass = <%= ask_vault_pass %>
20
+ <% end %>
21
+ <% unless force_remote_user.nil? %>
22
+ ansible.force_remote_user = <%= force_remote_user %>
23
+ <% end %>
24
+ <% unless host_key_checking.nil? %>
25
+ ansible.host_key_checking = <%= host_key_checking %>
26
+ <% end %>
27
+ <% unless host_vars.nil? %>
28
+ ansible.host_vars = <%= host_vars %>
29
+ <% end %>
30
+ <% unless raw_ssh_args.nil? %>
31
+ ansible.raw_ssh_args = <%= raw_ssh_args %>
32
+ <% end %>
33
+ <% unless raw_arguments.nil? %>
34
+ ansible.raw_arguments = <%= raw_arguments %>
35
+ <% end %>
36
+ end
@@ -0,0 +1,47 @@
1
+ module VagrantPlugins
2
+ module Invade
3
+ module InvadeModule
4
+ module AnsibleLocal
5
+
6
+ class AnsibleLocal < InvadeModule
7
+
8
+ attr_reader :result
9
+ attr_accessor :machine_name, :ansible_local_data
10
+
11
+ def initialize(machine_name, ansible_local_data, result: nil)
12
+ @machine_name = machine_name
13
+ @ansible_local_data = ansible_local_data
14
+ @result = result
15
+ end
16
+
17
+ def build
18
+ b = binding
19
+
20
+ begin
21
+
22
+ # Get machine name
23
+ machine_name = @machine_name
24
+
25
+ # Values for ansible_local provisioner section
26
+ playbook = @ansible_local_data['playbook']
27
+ verbose = @ansible_local_data['verbose']
28
+ install = @ansible_local_data['install']
29
+ install_mode = @ansible_local_data['install_mode']
30
+ limit = @ansible_local_data['limit']
31
+ inventory_path = @ansible_local_data['inventory_path']
32
+ provisioning_path = @ansible_local_data['provisioning_path']
33
+ tmp_path = @ansible_local_data['tmp_path']
34
+ version = @ansible_local_data['version']
35
+
36
+ eruby = Erubis::Eruby.new(File.read(self.get_template_path(__FILE__)))
37
+ @result = eruby.result b
38
+ rescue TypeError, SyntaxError, SystemCallError => e
39
+ raise(e)
40
+ end
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,27 @@
1
+ playbook:
2
+ type: String
3
+ default: nil
4
+ verbose:
5
+ type: Boolean
6
+ default: nil
7
+ install:
8
+ type: Boolean
9
+ default: nil
10
+ install_mode:
11
+ type: Symbol
12
+ default: :default
13
+ limit:
14
+ type: String
15
+ default: nil
16
+ inventory_path:
17
+ type: String
18
+ default: nil
19
+ provisioning_path:
20
+ type: String
21
+ default: nil
22
+ tmp_path:
23
+ type: String
24
+ default: nil
25
+ version:
26
+ type: String
27
+ default: nil
@@ -0,0 +1,30 @@
1
+
2
+ <%= machine_name %>.vm.provision "ansible_local" do |ansible|
3
+ <% unless playbook.nil? %>
4
+ ansible.playbook = '<%= playbook %>'
5
+ <% end %>
6
+ <% unless verbose.nil? %>
7
+ ansible.verbose = <%= verbose %>
8
+ <% end %>
9
+ <% unless install.nil? %>
10
+ ansible.install = <%= install %>
11
+ <% end %>
12
+ <% unless install_mode.nil? %>
13
+ ansible.install_mode = <%= install_mode %>
14
+ <% end %>
15
+ <% unless limit.nil? %>
16
+ ansible.limit = '<%= limit %>'
17
+ <% end %>
18
+ <% unless inventory_path.nil? %>
19
+ ansible.inventory_path = '<%= inventory_path %>'
20
+ <% end %>
21
+ <% unless provisioning_path.nil? %>
22
+ ansible.provisioning_path = '<%= provisioning_path %>'
23
+ <% end %>
24
+ <% unless tmp_path.nil? %>
25
+ ansible.tmp_path = '<%= tmp_path %>'
26
+ <% end %>
27
+ <% unless version.nil? %>
28
+ ansible.version = '<%= version %>'
29
+ <% end %>
30
+ end
@@ -3,10 +3,12 @@ module VagrantPlugins
3
3
  module InvadeModule
4
4
  module Provision
5
5
 
6
- autoload :Shell, 'vagrant-invade/module/provision/shell/shell'
6
+ autoload :Ansible, 'vagrant-invade/module/provision/ansible/ansible'
7
+ autoload :AnsibleLocal, 'vagrant-invade/module/provision/ansible_local/ansible_local'
7
8
  autoload :PuppetApply, 'vagrant-invade/module/provision/puppet_apply/puppet_apply'
8
9
  autoload :PuppetAgent, 'vagrant-invade/module/provision/puppet_agent/puppet_agent'
9
10
  autoload :Salt, 'vagrant-invade/module/provision/salt/salt'
11
+ autoload :Shell, 'vagrant-invade/module/provision/shell/shell'
10
12
 
11
13
  end
12
14
  end
@@ -11,7 +11,7 @@ install_syncdir:
11
11
  type: Boolean
12
12
  default: false
13
13
  install_type:
14
- type: String
14
+ type: Symbol
15
15
  default: :stable
16
16
  install_args:
17
17
  type: String
@@ -3,7 +3,7 @@
3
3
 
4
4
  Vagrant.configure(2) do |config|
5
5
 
6
- <% machines.each do |_, data| %>
6
+ <% machine.each do |_, data| %>
7
7
  <%= data %>
8
8
  <% end %>
9
9
  <%= global_hostmanager %>
@@ -21,7 +21,7 @@ module VagrantPlugins
21
21
  # Set variables for template files
22
22
  global_hostmanager = @vagrantfile_data['hostmanager']
23
23
  global_nfs = @vagrantfile_data['nfs']
24
- machines = @vagrantfile_data['machines']
24
+ machine = @vagrantfile_data['machine']
25
25
 
26
26
  eruby = Erubis::Eruby.new(File.read(self.get_template_path(__FILE__)))
27
27
  @result = eruby.result b
@@ -8,6 +8,7 @@ module VagrantPlugins
8
8
  autoload :IntegerValidator, 'vagrant-invade/validator/type/type_integer'
9
9
  autoload :StringOrArrayValidator, 'vagrant-invade/validator/type/type_string_array'
10
10
  autoload :StringValidator, 'vagrant-invade/validator/type/type_string'
11
+ autoload :SymbolValidator, 'vagrant-invade/validator/type/type_symbol'
11
12
  end
12
13
  end
13
14
  end
@@ -0,0 +1,38 @@
1
+ module VagrantPlugins
2
+ module Invade
3
+ module Validator
4
+ module Type
5
+
6
+ class SymbolValidator
7
+
8
+ attr_accessor :value, :name, :default, :env
9
+
10
+ def initialize(value, name, default, env)
11
+ @value = value
12
+ @name = name
13
+ @default = default
14
+ @env = env
15
+ end
16
+
17
+ def validate
18
+
19
+ if @value.is_a?(Symbol)
20
+ @env[:ui].success("\t#{@name} => #{@value}") unless @env[:invade_validate_quiet]
21
+ elsif @value === nil
22
+ @env[:ui].warn("\t#{@name} not set. Use Vagrant default.") unless @env[:invade_validate_quiet]
23
+
24
+ return @default
25
+ else
26
+ @env[:ui].error("\tError: '#{@value}' is not an Symbol. Set '#{@name}' to default value #{@default}.") unless @env[:invade_validate_quiet]
27
+
28
+ return @default
29
+ end
30
+
31
+ @value
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Invade
3
- VERSION = '0.7.0'
3
+ VERSION = '0.8.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-invade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lennart Stein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-20 00:00:00.000000000 Z
11
+ date: 2017-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,15 +61,17 @@ files:
61
61
  - images/invade-logo-128.png
62
62
  - images/invade-logo-256.png
63
63
  - images/invade-logo-512.png
64
- - invade.yml.dist
64
+ - invade-default.yml
65
65
  - lib/vagrant-invade.rb
66
66
  - lib/vagrant-invade/action.rb
67
+ - lib/vagrant-invade/action/check.rb
67
68
  - lib/vagrant-invade/action/config.rb
68
69
  - lib/vagrant-invade/action/create.rb
69
70
  - lib/vagrant-invade/action/init.rb
70
71
  - lib/vagrant-invade/action/process.rb
71
72
  - lib/vagrant-invade/command/base.rb
72
73
  - lib/vagrant-invade/command/build.rb
74
+ - lib/vagrant-invade/command/check.rb
73
75
  - lib/vagrant-invade/command/init.rb
74
76
  - lib/vagrant-invade/command/root.rb
75
77
  - lib/vagrant-invade/command/validate.rb
@@ -112,6 +114,12 @@ files:
112
114
  - lib/vagrant-invade/module/provider/vmware/rules.yml
113
115
  - lib/vagrant-invade/module/provider/vmware/template.erb
114
116
  - lib/vagrant-invade/module/provider/vmware/vmware.rb
117
+ - lib/vagrant-invade/module/provision/ansible/ansible.rb
118
+ - lib/vagrant-invade/module/provision/ansible/rules.yml
119
+ - lib/vagrant-invade/module/provision/ansible/template.erb
120
+ - lib/vagrant-invade/module/provision/ansible_local/ansible_local.rb
121
+ - lib/vagrant-invade/module/provision/ansible_local/rules.yml
122
+ - lib/vagrant-invade/module/provision/ansible_local/template.erb
115
123
  - lib/vagrant-invade/module/provision/provision.rb
116
124
  - lib/vagrant-invade/module/provision/puppet_agent/puppet_agent.rb
117
125
  - lib/vagrant-invade/module/provision/puppet_agent/rules.yml
@@ -154,6 +162,7 @@ files:
154
162
  - lib/vagrant-invade/validator/type/type_integer.rb
155
163
  - lib/vagrant-invade/validator/type/type_string.rb
156
164
  - lib/vagrant-invade/validator/type/type_string_array.rb
165
+ - lib/vagrant-invade/validator/type/type_symbol.rb
157
166
  - lib/vagrant-invade/version.rb
158
167
  - vagrant-invade.gemspec
159
168
  homepage: https://github.com/frgmt/vagrant-invade
@@ -1,102 +0,0 @@
1
- invade:
2
- # debug: true
3
-
4
- #hostmanager:
5
- # enabled: true
6
-
7
- # Machine settings. Each entry is one box
8
- machines:
9
-
10
- # Machine 1 (default)
11
- default:
12
-
13
- # VM related settings
14
- vm:
15
- box: boxcutter/debian82
16
- hostname: 'invade.vm'
17
-
18
- # Network settings
19
- network:
20
- private:
21
- ip: '10.42.133.7'
22
-
23
- # SSH settings
24
- ssh:
25
- forward_agent: true
26
-
27
- # Provider related settings. Performance, naming
28
- provider:
29
-
30
- vmware:
31
- name: 'invade'
32
- cores: 4
33
- memory: 512
34
-
35
- virtualbox:
36
- name: 'invade'
37
- cores: 4
38
- memory: 512
39
-
40
- # Synced Folder settings
41
- # synced_folder:
42
- # www:
43
- # type: nfs
44
- # path: '/www'
45
- # source: '..'
46
- # mount_options:
47
- # - nolock
48
- #
49
- # ssh:
50
- # type: nfs
51
- # path: '/home/vagrant/.ssh/'
52
- # source: '/Users/$USER/.ssh/'
53
-
54
- # provision:
55
- # set-permissions:
56
- # type: shell-inline
57
- # inline: 'chmod 777 /tmp'
58
-
59
- # run-composer:
60
- # type: shell
61
- # path: '/home/vagrant/provision/shell/run-composer.sh'
62
-
63
- # puppet-agent:
64
- # type: 'puppet'
65
- # manifests_path: 'puppet/manifests'
66
- # manifest_file: 'init.pp'
67
- # module_path:
68
- # - 'puppet/modules'
69
- # - 'puppet/vendor'
70
- # facter:
71
- # composer: true
72
- # shared_folder_type: 'nfs'
73
- # shared_folder_path: '/www'
74
- # package_state: 'present'
75
- # apt_update: true
76
-
77
- nfs:
78
- map_uid: Process.uid
79
- map_gid: Process.gid
80
- #functional: true
81
- #verify_installed: false
82
-
83
- plugin:
84
- #hostmanager:
85
- # aliases:
86
- # - my-1337-project.local
87
-
88
- #winnfsd:
89
- # enabled: true
90
- # loggin: false
91
-
92
- #r10k:
93
- # enabled: true
94
- # puppet_dir: 'puppet'
95
- # puppetfile_path: 'puppet/Puppetfile'
96
- # module_path: 'puppet/vendor'
97
- # modules:
98
- # ssh:
99
- # url: 'https://github.com/innogames/invade-puppet-ssh.git'
100
- # mysql:
101
- # url: 'https://github.com/example42/puppet-mysql.git'
102
- # version: '2.1.5'