Class: VagrantPlugins::AnsibleLocal::Provisioner

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-ansible-local/provisioner.rb

Instance Method Summary collapse

Instance Method Details

#configure(root_config) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/vagrant-ansible-local/provisioner.rb', line 5

def configure(root_config)
  playbook_path = Pathname.new(File.dirname(config.playbook)).expand_path(@machine.env.root_path)

  #folder_opts = {}
  #folder_opts[:nfs] = true if config.nfs
  #folder_opts[:owner] = "root" if !folder_opts[:nfs]

  # Share the playbook directory with the guest
  root_config.vm.synced_folder(playbook_path, config.guest_folder.to_s)
end

#provisionObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vagrant-ansible-local/provisioner.rb', line 16

def provision
 #       ssh = @machine.ssh_info

  # Connect with Vagrant user (unless --user or --private-key are overidden by 'raw_arguments')
  #options = %W[--private-key=#{ssh[:private_key_path]} --user=#{ssh[:username]}]
  options = %W[--connection=local]

  # Joker! Not (yet) supported arguments can be passed this way.
  options << "#{config.raw_arguments}" if config.raw_arguments

  # Append Provisioner options (highest precedence):
  if config.extra_vars
    extra_vars = config.extra_vars.map do |k,v|
      v = v.gsub('"', '\\"')
      if v.include?(' ')
        v = v.gsub("'", "\\'")
        v = "'#{v}'"
      end

      "#{k}=#{v}"
    end
    options << "--extra-vars=\"#{extra_vars.join(" ")}\""
  end

#        options << "--inventory-file=#{self.setup_inventory_file}"
#        options << "--sudo" if config.sudo
#        options << "--sudo-user=#{config.sudo_user}" if config.sudo_user
  options << "#{self.get_verbosity_argument}" if config.verbose
#        options << "--ask-sudo-pass" if config.ask_sudo_pass
  options << "--tags=#{as_list_argument(config.tags)}" if config.tags
  options << "--skip-tags=#{as_list_argument(config.skip_tags)}" if config.skip_tags
  options << "--limit=#{as_list_argument(config.limit)}" if config.limit
  options << "--start-at-task=#{config.start_at_task}" if config.start_at_task

  # Assemble the full ansible-playbook command
  command = "export ANSIBLE_FORCE_COLOR=true\n"
  command += "export ANSIBLE_HOST_KEY_CHECKING=#{config.host_key_checking}\n"
  command += "export PYTHONUNBUFFERED=1\n"
  command += (%w(ansible-playbook) << (File.join(config.guest_folder, File.basename(config.playbook).to_s)) << options).flatten.join(' ')



  @machine.communicate.tap do |comm|
    # Execute it with sudo
    comm.execute(command, sudo: config.privileged) do |type, data|
      if [:stderr, :stdout].include?(type)
        @machine.env.ui.info(data, :new_line => false, :prefix => false)
      end
    end
  end
end