@@ -264,6 +264,54 @@ class AnsibleRunnerSpec extends Specification{
264
264
265
265
}
266
266
267
+ def " test skip empty extra vars" () {
268
+ given :
269
+ String playbook = " test"
270
+ String privateKey = " privateKey"
271
+ String extraVars = " test: 123\n emptyVar: " // emptyVar is empty → should be skipped
272
+
273
+ def runnerBuilder = AnsibleRunner . playbookInline(playbook)
274
+ runnerBuilder. encryptExtraVars(true )
275
+ runnerBuilder. sshPrivateKey(privateKey)
276
+ runnerBuilder. extraVars(extraVars)
277
+
278
+ def process = Mock (Process ) {
279
+ waitFor() >> 0
280
+ getInputStream() >> new ByteArrayInputStream (" " . getBytes())
281
+ getOutputStream() >> new ByteArrayOutputStream ()
282
+ getErrorStream() >> new ByteArrayInputStream (" " . getBytes())
283
+ }
284
+
285
+ def processExecutor = Mock (ProcessExecutor ) {
286
+ run() >> process
287
+ }
288
+
289
+ def processBuilder = Mock (ProcessExecutor.ProcessExecutorBuilder ) {
290
+ build() >> processExecutor
291
+ }
292
+
293
+ def ansibleVault = Mock (AnsibleVault ) {
294
+ checkAnsibleVault() >> true
295
+ getVaultPasswordScriptFile() >> new File (" vault-script-client.py" )
296
+ }
297
+
298
+ runnerBuilder. processExecutorBuilder(processBuilder)
299
+ runnerBuilder. ansibleVault(ansibleVault)
300
+ runnerBuilder. customTmpDirPath(" /tmp" )
301
+
302
+ when :
303
+ AnsibleRunner runner = runnerBuilder. build()
304
+ def result = runner. run()
305
+
306
+ then :
307
+ // Only 1 encryptVariable call — "test" — "emptyVar" is skipped
308
+ 1 * ansibleVault. encryptVariable(_,_) >> " !vault | value"
309
+ result == 0
310
+ ! runner. getTempPlaybook(). exists()
311
+ ! runner. getTempVarsFile(). exists()
312
+ }
313
+
314
+
267
315
def " test password authentication with encrypted extra vars " (){
268
316
given :
269
317
0 commit comments