diff --git a/CHANGELOG.md b/CHANGELOG.md index 64cce4c0f..3f708de91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ FEATURES: This new abstraction allows plugins to define "capabilities" that certain guest operating systems can implement. This allows greater flexibility in doing guest-specific behavior. + - Ansible provisioner support. [GH-1465] IMPROVEMENTS: diff --git a/plugins/provisioners/ansible/provisioner.rb b/plugins/provisioners/ansible/provisioner.rb index e744663c8..e70e2bc0b 100644 --- a/plugins/provisioners/ansible/provisioner.rb +++ b/plugins/provisioners/ansible/provisioner.rb @@ -3,11 +3,12 @@ module VagrantPlugins class Provisioner < Vagrant.plugin("2", :provisioner) def provision ssh = @machine.ssh_info - + options = %W[--private-key=#{ssh[:private_key_path]} --user=#{ssh[:username]}] options << "--extra-vars=\"#{config.extra_vars}\"" if config.extra_vars options << "--inventory-file=#{config.inventory_file}" if config.inventory_file options << "--ask-sudo-pass" if config.ask_sudo_pass + if config.limit if not config.limit.kind_of?(Array) config.limit = [config.limit] @@ -15,21 +16,24 @@ module VagrantPlugins config.limit = config.limit.join(",") options << "--limit=#{config.limit}" end + options << "--sudo" if config.sudo options << "--sudo-user=#{config.sudo_user}" if config.sudo_user options << "--verbose" if config.verbose - + # Assemble the full ansible-playbook command command = (%w(ansible-playbook) << options << config.playbook).flatten - + # Write stdout and stderr data, since it's the regular Ansible output command << { :env => { "ANSIBLE_FORCE_COLOR" => "true" }, :notify => [:stdout, :stderr] } + Vagrant::Util::Subprocess.execute(*command) do |type, data| - puts "#{data}" if type == :stdout || type == :stderr - yield type, data if block_given? + if type == :stdout || type == :stderr + @machine.env.ui.info(data.chomp, :prefix => false) + end end end end