From 44960891164d02aeacc6217f6494e709787cffaf Mon Sep 17 00:00:00 2001 From: Jesus Osuna Date: Tue, 19 Nov 2024 10:29:18 -0300 Subject: [PATCH] evaluate runner tmp dir --- .../plugins/ansible/util/AnsibleUtil.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/groovy/com/rundeck/plugins/ansible/util/AnsibleUtil.java b/src/main/groovy/com/rundeck/plugins/ansible/util/AnsibleUtil.java index c59050a..d6441ea 100644 --- a/src/main/groovy/com/rundeck/plugins/ansible/util/AnsibleUtil.java +++ b/src/main/groovy/com/rundeck/plugins/ansible/util/AnsibleUtil.java @@ -16,6 +16,11 @@ public class AnsibleUtil { + public static final String RUNNER_OVERRIDE_TMP_DIR = "runner.rundeck.overrideTempDir"; + public static final String RUNNER_DIRS_TMP = "runner.dirs.tmp" ; + public static final String ANSIBLE_CUSTOM_TMP_DIR = "ansible.custom.tmp.dir"; + public static final String DEFAULT_TMP_DIR = "java.io.tmpdir"; + public static SecretBundle createBundle(AnsibleRunnerContextBuilder builder){ DefaultSecretBundle secretBundle = new DefaultSecretBundle(); @@ -109,20 +114,27 @@ public static File createTemporaryFile(String suffix, String data) throws IOExce } public static File createTemporaryFile(String prefix, String suffix, String data) throws IOException { - return createTemporaryFile(new File(getAnsibleTmpPath()), suffix, data, prefix); + return createTemporaryFile(prefix, suffix, data, new File(getAnsibleTmpPath())); } - public static File createTemporaryFile(File path, String suffix, String data, String prefix) throws IOException { + public static File createTemporaryFile( String prefix, String suffix, String data, File path) throws IOException { File tempVarsFile = File.createTempFile(prefix, suffix, path); Files.write(tempVarsFile.toPath(), data.getBytes()); return tempVarsFile; } public static String getAnsibleTmpPath() { - return System.getProperty("ansible.tmp.path", System.getProperty("java.io.tmpdir")); + if( Boolean.getBoolean(System.getProperty(RUNNER_OVERRIDE_TMP_DIR,"false")) + && !System.getProperty(RUNNER_DIRS_TMP,"").isEmpty()){ + return System.getProperty(RUNNER_DIRS_TMP); + } + if( !Boolean.getBoolean(System.getProperty(RUNNER_OVERRIDE_TMP_DIR,"false")) + && !System.getProperty(ANSIBLE_CUSTOM_TMP_DIR,"").isEmpty()){ + return System.getProperty(ANSIBLE_CUSTOM_TMP_DIR); + } + return System.getProperty(DEFAULT_TMP_DIR); } - public static String randomString(){ byte[] bytes = new byte[32]; new SecureRandom().nextBytes(bytes);