diff --git a/plugins/provisioners/ansible/config.rb b/plugins/provisioners/ansible/config.rb index 0d20915a9..df265698b 100644 --- a/plugins/provisioners/ansible/config.rb +++ b/plugins/provisioners/ansible/config.rb @@ -9,6 +9,12 @@ module VagrantPlugins attr_accessor :sudo attr_accessor :sudo_user attr_accessor :verbose + attr_accessor :tags + attr_accessor :skip_tags + attr_accessor :start_at_task + + # Joker attribute, used to pass unsupported arguments to ansible anyway + attr_accessor :raw_arguments def initialize @playbook = UNSET_VALUE @@ -19,6 +25,10 @@ module VagrantPlugins @sudo = UNSET_VALUE @sudo_user = UNSET_VALUE @verbose = UNSET_VALUE + @tags = UNSET_VALUE + @skip_tags = UNSET_VALUE + @start_at_task = UNSET_VALUE + @raw_arguments = UNSET_VALUE end def finalize! @@ -30,6 +40,10 @@ module VagrantPlugins @sudo = nil if @sudo == UNSET_VALUE @sudo_user = nil if @sudo_user == UNSET_VALUE @verbose = nil if @verbose == UNSET_VALUE + @tags = nil if @tags == UNSET_VALUE + @skip_tags = nil if @skip_tags == UNSET_VALUE + @start_at_task = nil if @start_at_task == UNSET_VALUE + @raw_arguments = nil if @raw_arguments == UNSET_VALUE end def validate(machine) diff --git a/plugins/provisioners/ansible/provisioner.rb b/plugins/provisioners/ansible/provisioner.rb index 8a1bd2cef..03e859917 100644 --- a/plugins/provisioners/ansible/provisioner.rb +++ b/plugins/provisioners/ansible/provisioner.rb @@ -3,8 +3,13 @@ module VagrantPlugins class Provisioner < Vagrant.plugin("2", :provisioner) def provision ssh = @machine.ssh_info + inventory_file_path = self.setup_inventory_file options = %W[--private-key=#{ssh[:private_key_path]} --user=#{ssh[:username]}] + + # Joker! Not (yet) supported arguments can be passed this way. + options << "#{config.raw_arguments}" if config.raw_arguments + options << "--inventory-file=#{inventory_file_path}" options << "--ask-sudo-pass" if config.ask_sudo_pass @@ -36,6 +41,12 @@ module VagrantPlugins options << (config.verbose.to_s == "extra" ? "-vvv" : "--verbose") end + # Append Provisioner options (higher precedence): + 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 = (%w(ansible-playbook) << options << config.playbook).flatten @@ -74,6 +85,12 @@ module VagrantPlugins return generated_inventory_file.to_s end + + protected + + def as_list_argument(v) + v.kind_of?(Array) ? v.join(',') : v + end end end end