@@ -39,6 +39,7 @@ class AnsiblePush < Base
3939 default_config :host_key_checking , false
4040 default_config :mygroup , nil
4141 default_config :playbook , nil
42+ default_config :playbooks , [ ]
4243 default_config :generate_inv , true
4344 default_config :generate_inv_path , '`which kitchen-ansible-inventory`'
4445 default_config :raw_arguments , nil
@@ -66,9 +67,24 @@ class AnsiblePush < Base
6667 def conf
6768 return @validated_config if defined? @validated_config
6869
69- raise UserError , 'No playbook defined. Please specify one in .kitchen.yml' unless config [ :playbook ]
70+ unless config [ :playbooks ] . is_a? ( Array )
71+ raise UserError ,
72+ "ansible playbooks is not an `Array` type. Given type: #{ config [ :playbooks ] . class } "
73+ end
74+
75+ playbooks_to_run = config [ :playbooks ] . clone
76+
77+ if config [ :playbooks ] && config [ :playbook ]
78+ playbooks_to_run << config [ :playbook ]
79+ end
7080
71- raise UserError , "playbook '#{ config [ :playbook ] } ' could not be found. Please check path" unless File . exist? ( config [ :playbook ] )
81+ if !playbooks_to_run || playbooks_to_run . empty?
82+ raise UserError , 'No `playbook` or `playbooks` defined. Please specify one in .kitchen.yml'
83+ end
84+
85+ playbooks_to_run . each do |playbook |
86+ raise UserError , "playbook '#{ config [ :playbook ] } ' could not be found. Please check path" unless File . exist? ( playbook )
87+ end
7288
7389 if config [ :vault_password_file ] && !File . exist? ( config [ :vault_password_file ] )
7490 raise UserError , "Vault password '#{ config [ :vault_password_file ] } ' could not be found. Please check path"
@@ -167,10 +183,9 @@ def options
167183 @options = options
168184 end
169185
170- def command
171- return @command if defined? @command
186+ def command ( playbook )
172187 @command = [ conf [ :ansible_playbook_bin ] ]
173- @command = ( @command << options << conf [ : playbook] ) . flatten . join ( ' ' )
188+ @command = ( @command << options << playbook ) . flatten . join ( ' ' )
174189 debug ( "Ansible push command= #{ @command } " )
175190 @command
176191 end
@@ -209,7 +224,7 @@ def true_command
209224 def install_command
210225 info ( '*************** AnsiblePush install_command ***************' )
211226 # Test if ansible-playbook is installed and give a meaningful error message
212- version_check = command + ' --version'
227+ version_check = command ( conf [ :playbooks ] . first ) + ' --version'
213228 _ , stdout , stderr , wait_thr = Open3 . popen3 ( command_env , version_check )
214229 exit_status = wait_thr . value
215230 raise UserError , "#{ version_check } returned a non zero '#{ exit_status } ' stdout : '#{ stdout . read } ', stderr: '#{ stderr . read } '" unless exit_status . success?
@@ -232,8 +247,11 @@ def chef_installation(chef_url, omnibus_download_dir)
232247
233248 def run_command
234249 info ( '*************** AnsiblePush run ***************' )
235- exec_ansible_command ( command_env , command , 'ansible-playbook' )
236- idempotency_test if conf [ :idempotency_test ]
250+ conf [ :playbooks ] . each do |playbook |
251+ exec_ansible_command ( command_env , command ( playbook ) , 'ansible-playbook' )
252+ idempotency_test if conf [ :idempotency_test ]
253+ end
254+
237255 info ( '*************** AnsiblePush end run *******************' )
238256 debug ( "[#{ name } ] Converge completed (#{ conf [ :sleep ] } s)." )
239257 true_command # Place holder so a string is returned. This will execute true on remote host
0 commit comments