From 7bc6dd8a33fdcd2d45d9d93ad2cc89e94d042529 Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Mon, 6 May 2013 21:17:45 +0200 Subject: [PATCH 1/7] Add support for "ansible.tags" attribute --- plugins/provisioners/ansible/config.rb | 3 +++ plugins/provisioners/ansible/provisioner.rb | 17 ++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/provisioners/ansible/config.rb b/plugins/provisioners/ansible/config.rb index beaea5466..98dfb73a7 100644 --- a/plugins/provisioners/ansible/config.rb +++ b/plugins/provisioners/ansible/config.rb @@ -9,6 +9,7 @@ module VagrantPlugins attr_accessor :sudo attr_accessor :sudo_user attr_accessor :verbose + attr_accessor :tags def initialize @playbook = UNSET_VALUE @@ -19,6 +20,7 @@ module VagrantPlugins @sudo = UNSET_VALUE @sudo_user = UNSET_VALUE @verbose = UNSET_VALUE + @tags = UNSET_VALUE end def finalize! @@ -30,6 +32,7 @@ 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 end def validate(machine) diff --git a/plugins/provisioners/ansible/provisioner.rb b/plugins/provisioners/ansible/provisioner.rb index 8891f0357..d84f714dd 100644 --- a/plugins/provisioners/ansible/provisioner.rb +++ b/plugins/provisioners/ansible/provisioner.rb @@ -8,15 +8,8 @@ module VagrantPlugins options << "--extra-vars=" + config.extra_vars.map{|k,v| "#{k}=#{v}"}.join(' ') 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] - end - config.limit = config.limit.join(",") - options << "--limit=#{config.limit}" - end - + options << "--tags=#{as_list_argument(config.tags)}" if config.tags + options << "--limit=#{as_list_argument(config.limit)}" if config.limit options << "--sudo" if config.sudo options << "--sudo-user=#{config.sudo_user}" if config.sudo_user options << "--verbose" if config.verbose @@ -40,6 +33,12 @@ module VagrantPlugins raise Vagrant::Errors::AnsiblePlaybookAppNotFound end end + + private + + def as_list_argument(v) + v.kind_of?(Array) ? v.join(',') : v + end end end end From 66715de2aedc40daf405624012b5be7783b91e01 Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Mon, 6 May 2013 22:28:20 +0200 Subject: [PATCH 2/7] Add a Joker to pass raw options to ansible-playbook call --- plugins/provisioners/ansible/config.rb | 5 +++++ plugins/provisioners/ansible/provisioner.rb | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/plugins/provisioners/ansible/config.rb b/plugins/provisioners/ansible/config.rb index 98dfb73a7..35c972877 100644 --- a/plugins/provisioners/ansible/config.rb +++ b/plugins/provisioners/ansible/config.rb @@ -11,6 +11,9 @@ module VagrantPlugins attr_accessor :verbose attr_accessor :tags + # Joker attribute, used to pass unsupported arguments to ansible anyway + attr_accessor :raw_arguments + def initialize @playbook = UNSET_VALUE @extra_vars = UNSET_VALUE @@ -21,6 +24,7 @@ module VagrantPlugins @sudo_user = UNSET_VALUE @verbose = UNSET_VALUE @tags = UNSET_VALUE + @raw_arguments = UNSET_VALUE end def finalize! @@ -33,6 +37,7 @@ module VagrantPlugins @sudo_user = nil if @sudo_user == UNSET_VALUE @verbose = nil if @verbose == UNSET_VALUE @tags = nil if @tags == 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 d84f714dd..1f51d5323 100644 --- a/plugins/provisioners/ansible/provisioner.rb +++ b/plugins/provisioners/ansible/provisioner.rb @@ -4,7 +4,13 @@ module VagrantPlugins 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]}] + + # Joker! Not (yet) supported arguments can be passed this way. + options << "#{config.raw_arguments}" if config.raw_arguments + + # Append Provisioner options (higher precedence): options << "--extra-vars=" + config.extra_vars.map{|k,v| "#{k}=#{v}"}.join(' ') if config.extra_vars options << "--inventory-file=#{config.inventory_file}" if config.inventory_file options << "--ask-sudo-pass" if config.ask_sudo_pass From 96fb28dcf9f616d226f9bb25fe52a1a4f17368f9 Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Mon, 6 May 2013 23:01:27 +0200 Subject: [PATCH 3/7] Support different verbosity levels with 'ansible.verbose' --- plugins/provisioners/ansible/provisioner.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/provisioners/ansible/provisioner.rb b/plugins/provisioners/ansible/provisioner.rb index 1f51d5323..c0388121b 100644 --- a/plugins/provisioners/ansible/provisioner.rb +++ b/plugins/provisioners/ansible/provisioner.rb @@ -18,7 +18,15 @@ module VagrantPlugins options << "--limit=#{as_list_argument(config.limit)}" if config.limit options << "--sudo" if config.sudo options << "--sudo-user=#{config.sudo_user}" if config.sudo_user - options << "--verbose" if config.verbose + if config.verbose + if config.verbose.is_a? String + if config.verbose =~ /v+$/ + options << "--#{config.verbose}" + end + else + options << "--verbose" + end + end # Assemble the full ansible-playbook command command = (%w(ansible-playbook) << options << config.playbook).flatten From cc4734dfc1f4ef63caf80ec990eb1a0f1a4ac5c0 Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Tue, 7 May 2013 16:57:13 +0200 Subject: [PATCH 4/7] Fix typo error (single dash: -vv not --vv) --- plugins/provisioners/ansible/provisioner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/provisioners/ansible/provisioner.rb b/plugins/provisioners/ansible/provisioner.rb index c0388121b..1d06a4a18 100644 --- a/plugins/provisioners/ansible/provisioner.rb +++ b/plugins/provisioners/ansible/provisioner.rb @@ -21,7 +21,7 @@ module VagrantPlugins if config.verbose if config.verbose.is_a? String if config.verbose =~ /v+$/ - options << "--#{config.verbose}" + options << "-#{config.verbose}" end else options << "--verbose" From f2e9562e5fe190d44b4b1499be091b317cfa8a1d Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Tue, 14 May 2013 05:25:28 +0200 Subject: [PATCH 5/7] Add support for "ansible.start_at_task" attribute --- plugins/provisioners/ansible/config.rb | 3 +++ plugins/provisioners/ansible/provisioner.rb | 1 + 2 files changed, 4 insertions(+) diff --git a/plugins/provisioners/ansible/config.rb b/plugins/provisioners/ansible/config.rb index 35c972877..d3a8c042b 100644 --- a/plugins/provisioners/ansible/config.rb +++ b/plugins/provisioners/ansible/config.rb @@ -10,6 +10,7 @@ module VagrantPlugins attr_accessor :sudo_user attr_accessor :verbose attr_accessor :tags + attr_accessor :start_at_task # Joker attribute, used to pass unsupported arguments to ansible anyway attr_accessor :raw_arguments @@ -24,6 +25,7 @@ module VagrantPlugins @sudo_user = UNSET_VALUE @verbose = UNSET_VALUE @tags = UNSET_VALUE + @start_at_task = UNSET_VALUE @raw_arguments = UNSET_VALUE end @@ -37,6 +39,7 @@ module VagrantPlugins @sudo_user = nil if @sudo_user == UNSET_VALUE @verbose = nil if @verbose == UNSET_VALUE @tags = nil if @tags == UNSET_VALUE + @start_at_task = nil if @start_at_task == UNSET_VALUE @raw_arguments = nil if @raw_arguments == UNSET_VALUE end diff --git a/plugins/provisioners/ansible/provisioner.rb b/plugins/provisioners/ansible/provisioner.rb index 1d06a4a18..29c08fbd4 100644 --- a/plugins/provisioners/ansible/provisioner.rb +++ b/plugins/provisioners/ansible/provisioner.rb @@ -16,6 +16,7 @@ module VagrantPlugins options << "--ask-sudo-pass" if config.ask_sudo_pass options << "--tags=#{as_list_argument(config.tags)}" if config.tags options << "--limit=#{as_list_argument(config.limit)}" if config.limit + options << "--start-at-task=#{config.start_at_task}" if config.start_at_task options << "--sudo" if config.sudo options << "--sudo-user=#{config.sudo_user}" if config.sudo_user if config.verbose From 8d5b614231b673c67ab7cb6d64cda759bb2bf2e9 Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Tue, 14 May 2013 05:26:26 +0200 Subject: [PATCH 6/7] protected not private --- plugins/provisioners/ansible/provisioner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/provisioners/ansible/provisioner.rb b/plugins/provisioners/ansible/provisioner.rb index 29c08fbd4..46d1528d0 100644 --- a/plugins/provisioners/ansible/provisioner.rb +++ b/plugins/provisioners/ansible/provisioner.rb @@ -49,7 +49,7 @@ module VagrantPlugins end end - private + protected def as_list_argument(v) v.kind_of?(Array) ? v.join(',') : v From b061e02bc804fc779c5b896d3cea03fffe92d216 Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Mon, 12 Aug 2013 09:41:18 +0200 Subject: [PATCH 7/7] Add support for "ansible.skip_tags" attribute --- plugins/provisioners/ansible/config.rb | 3 +++ plugins/provisioners/ansible/provisioner.rb | 1 + 2 files changed, 4 insertions(+) diff --git a/plugins/provisioners/ansible/config.rb b/plugins/provisioners/ansible/config.rb index d3a8c042b..54fe4c8a2 100644 --- a/plugins/provisioners/ansible/config.rb +++ b/plugins/provisioners/ansible/config.rb @@ -10,6 +10,7 @@ module VagrantPlugins 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 @@ -25,6 +26,7 @@ module VagrantPlugins @sudo_user = UNSET_VALUE @verbose = UNSET_VALUE @tags = UNSET_VALUE + @skip_tags = UNSET_VALUE @start_at_task = UNSET_VALUE @raw_arguments = UNSET_VALUE end @@ -39,6 +41,7 @@ module VagrantPlugins @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 diff --git a/plugins/provisioners/ansible/provisioner.rb b/plugins/provisioners/ansible/provisioner.rb index 46d1528d0..8d57d9036 100644 --- a/plugins/provisioners/ansible/provisioner.rb +++ b/plugins/provisioners/ansible/provisioner.rb @@ -15,6 +15,7 @@ module VagrantPlugins options << "--inventory-file=#{config.inventory_file}" if config.inventory_file 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 options << "--sudo" if config.sudo