@@ -292,6 +292,8 @@ public static AnsibleRunner buildAnsibleRunner(AnsibleRunnerContextBuilder conte
292
292
File tempBecameVarsFile ;
293
293
File vaultPromptFile ;
294
294
295
+ String customTmpDirPath ;
296
+
295
297
public void deleteTempDirectory (Path tempDirectory ) throws IOException {
296
298
Files .walkFileTree (tempDirectory , new SimpleFileVisitor <Path >() {
297
299
@ Override
@@ -333,11 +335,11 @@ public int run() throws Exception {
333
335
if (baseDirectory == null ) {
334
336
// Use a temporary directory and mark it for possible removal later
335
337
this .usingTempDirectory = true ;
336
- baseDirectory = Files .createTempDirectory ("ansible-rundeck" );
338
+ baseDirectory = Files .createTempDirectory (Path . of ( customTmpDirPath ), "ansible-rundeck" );
337
339
}
338
340
339
341
if (ansibleVault ==null ){
340
- tempInternalVaultFile = AnsibleVault .createVaultScriptAuth ("ansible-script-vault" );
342
+ tempInternalVaultFile = AnsibleVault .createVaultScriptAuth ("ansible-script-vault" , customTmpDirPath );
341
343
ansibleVault = AnsibleVault .builder ()
342
344
.baseDirectory (baseDirectory )
343
345
.masterPassword (AnsibleUtil .randomString ())
@@ -373,7 +375,7 @@ public int run() throws Exception {
373
375
} else if (type == AnsibleCommand .PlaybookPath ) {
374
376
procArgs .add (playbook );
375
377
} else if (type == AnsibleCommand .PlaybookInline ) {
376
- tempPlaybook = AnsibleUtil .createTemporaryFile ("playbook" , playbook );
378
+ tempPlaybook = AnsibleUtil .createTemporaryFile ("" , " playbook" , playbook , customTmpDirPath );
377
379
procArgs .add (tempPlaybook .getAbsolutePath ());
378
380
}
379
381
@@ -405,7 +407,7 @@ public int run() throws Exception {
405
407
for (String limit : limits ) {
406
408
sb .append (limit ).append ("\n " );
407
409
}
408
- tempFile = AnsibleUtil .createTemporaryFile ("targets" , sb .toString ());
410
+ tempFile = AnsibleUtil .createTemporaryFile ("" , " targets" , sb .toString (), customTmpDirPath );
409
411
410
412
procArgs .add ("-l" );
411
413
procArgs .add ("@" + tempFile .getAbsolutePath ());
@@ -422,13 +424,13 @@ public int run() throws Exception {
422
424
addeExtraVars = encryptExtraVarsKey (extraVars );
423
425
}
424
426
425
- tempVarsFile = AnsibleUtil .createTemporaryFile ("extra-vars" , addeExtraVars );
427
+ tempVarsFile = AnsibleUtil .createTemporaryFile ("" , " extra-vars" , addeExtraVars , customTmpDirPath );
426
428
procArgs .add ("--extra-vars" + "=" + "@" + tempVarsFile .getAbsolutePath ());
427
429
}
428
430
429
431
if (sshPrivateKey != null && !sshPrivateKey .isEmpty ()) {
430
432
String privateKeyData = sshPrivateKey .replaceAll ("\r \n " , "\n " );
431
- tempPkFile = AnsibleUtil .createTemporaryFile ("id_rsa" , privateKeyData );
433
+ tempPkFile = AnsibleUtil .createTemporaryFile ("" , " id_rsa" , privateKeyData , customTmpDirPath );
432
434
433
435
// Only the owner can read and write
434
436
Set <PosixFilePermission > perms = new HashSet <PosixFilePermission >();
@@ -454,7 +456,7 @@ public int run() throws Exception {
454
456
finalextraVarsPassword = encryptExtraVarsKey (extraVarsPassword );
455
457
}
456
458
457
- tempSshVarsFile = AnsibleUtil .createTemporaryFile ("ssh-extra-vars" , finalextraVarsPassword );
459
+ tempSshVarsFile = AnsibleUtil .createTemporaryFile ("" , " ssh-extra-vars" , finalextraVarsPassword , customTmpDirPath );
458
460
procArgs .add ("--extra-vars" + "=" + "@" + tempSshVarsFile .getAbsolutePath ());
459
461
}
460
462
@@ -473,7 +475,7 @@ public int run() throws Exception {
473
475
finalextraVarsPassword = encryptExtraVarsKey (extraVarsPassword );
474
476
}
475
477
476
- tempBecameVarsFile = AnsibleUtil .createTemporaryFile ("become-extra-vars" , finalextraVarsPassword );
478
+ tempBecameVarsFile = AnsibleUtil .createTemporaryFile ("" , " become-extra-vars" , finalextraVarsPassword , customTmpDirPath );
477
479
procArgs .add ("--extra-vars" + "=" + "@" + tempBecameVarsFile .getAbsolutePath ());
478
480
}
479
481
}
@@ -531,7 +533,7 @@ public int run() throws Exception {
531
533
List <VaultPrompt > stdinVariables = new ArrayList <>();
532
534
533
535
if (useAnsibleVault || vaultPass != null ){
534
- vaultPromptFile = File . createTempFile ("vault-prompt" , ".log" );
536
+ vaultPromptFile = AnsibleUtil . createTemporaryFile ("vault-prompt" ,".log" , "" , customTmpDirPath );
535
537
}
536
538
537
539
if (useAnsibleVault ) {
@@ -677,7 +679,7 @@ public boolean registerKeySshAgent(String keyPath) throws Exception {
677
679
678
680
File tempPassVarsFile = null ;
679
681
if (sshPassphrase != null && sshPassphrase .length () > 0 ) {
680
- tempPassVarsFile = File . createTempFile ( "ansible-runner" , "ssh-add-check" );
682
+ tempPassVarsFile = AnsibleUtil . createTemporaryFile ( "" , "ssh-add-check" , "" , customTmpDirPath );
681
683
tempPassVarsFile .setExecutable (true );
682
684
683
685
List <String > passScript = new ArrayList <>();
0 commit comments