Skip to content

Commit

Permalink
evaluate runner tmp dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesus-Osuna-M committed Nov 19, 2024
1 parent da85fe9 commit 4496089
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/groovy/com/rundeck/plugins/ansible/util/AnsibleUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4496089

Please sign in to comment.