Skip to content

Commit 902ec3b

Browse files
authored
Merge pull request #426 from rundeck-plugins/RUN-4228
[RUN-4228] Community PR - Allow Setting Ansible base dir project wide
2 parents 1760e47 + abed171 commit 902ec3b

12 files changed

Lines changed: 243 additions & 5 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ The following configuration attributes can be set on the Node, or in the project
6464

6565
* `ansible-inventory` - Specifies the ansible inventory to use, can define a global inventory file at the project level without requiring setting the same variable for each job. It is also possible to provide an inventory _inline_ to a job. The default is /etc/ansible/hosts.
6666
* `ansible-executable` - The executable to use for node Node Executor. (default /bin/sh)
67+
* `ansible-base-dir-path` - Set ansible base directory path. This can be set project-wide to specify the working directory for Ansible operations.
6768
* `ansible-limit` - Global groups limits can be set at the project level to filter hosts/groups from the Ansible inventory. See http://docs.ansible.com/ansible/intro_patterns.html for syntax help.
6869
* `ansible-vault-path` - Default vault file path to use for Playbook Jobs.
6970
* `ansible-vault-storage-path` - Specifies a [Key Storage Path][] to look up the ansible vault password from. If specified, it will be used instead of the `ansible-vault-path`.

src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleRunner.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,10 @@ public int run() throws Exception {
692692
processExecutorBuilder.baseDirectory(baseDirectory.toFile());
693693
}
694694

695+
if (debug) {
696+
System.out.println(" ansible-base-dir: " + (baseDirectory != null ? baseDirectory.toAbsolutePath() : "(not configured, using tmp dir)"));
697+
}
698+
695699
//SET env variables
696700
Map<String, String> processEnvironment = new HashMap<>();
697701

src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleRunnerContextBuilder.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -770,15 +770,33 @@ public String getConfigFile() {
770770
}
771771

772772
public String getBaseDir() {
773-
String baseDir = null;
774-
if (getJobConf().containsKey(AnsibleDescribable.ANSIBLE_BASE_DIR_PATH)) {
775-
baseDir = (String) jobConf.get(AnsibleDescribable.ANSIBLE_BASE_DIR_PATH);
773+
String baseDir;
774+
baseDir = PropertyResolver.resolveProperty(
775+
AnsibleDescribable.ANSIBLE_BASE_DIR_PATH,
776+
null,
777+
getFrameworkProject(),
778+
getFramework(),
779+
getNode(),
780+
getJobConf()
781+
);
782+
783+
if (null == baseDir || baseDir.isEmpty()) {
784+
if (this.pluginGroup != null && this.pluginGroup.getAnsibleBaseDirPath() != null && !this.pluginGroup.getAnsibleBaseDirPath().isEmpty()) {
785+
this.context.getExecutionLogger().log(
786+
4, "plugin group set getAnsibleBaseDirPath: " + this.pluginGroup.getAnsibleBaseDirPath()
787+
);
788+
baseDir = this.pluginGroup.getAnsibleBaseDirPath();
789+
}
776790
}
777791

792+
String resolved;
778793
if (null != baseDir && baseDir.contains("${")) {
779-
return DataContextUtils.replaceDataReferencesInString(baseDir, getContext().getDataContext());
794+
resolved = DataContextUtils.replaceDataReferencesInString(baseDir, getContext().getDataContext());
795+
} else {
796+
resolved = baseDir;
780797
}
781-
return baseDir;
798+
log.debug("[ansible] base-dir-path resolved to: {}", resolved != null ? resolved : "(not configured)");
799+
return resolved;
782800
}
783801

784802
public String getBinariesFilePath() {

src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleFileCopier.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class AnsibleFileCopier implements FileCopier, AnsibleDescribable, ProxyR
4040
builder.property(BINARIES_DIR_PATH_PROP);
4141
builder.property(INVENTORY_INLINE_PROP);
4242
builder.property(CONFIG_FILE_PATH);
43+
builder.property(BASE_DIR_PROP);
4344
builder.property(SSH_AUTH_TYPE_PROP);
4445
builder.property(SSH_USER_PROP);
4546
builder.property(SSH_PASSWORD_STORAGE_PROP);
@@ -60,6 +61,8 @@ public class AnsibleFileCopier implements FileCopier, AnsibleDescribable, ProxyR
6061
builder.frameworkMapping(ANSIBLE_BINARIES_DIR_PATH,FWK_PROP_PREFIX + ANSIBLE_BINARIES_DIR_PATH);
6162
builder.mapping(ANSIBLE_CONFIG_FILE_PATH,PROJ_PROP_PREFIX + ANSIBLE_CONFIG_FILE_PATH);
6263
builder.frameworkMapping(ANSIBLE_CONFIG_FILE_PATH,FWK_PROP_PREFIX + ANSIBLE_CONFIG_FILE_PATH);
64+
builder.mapping(ANSIBLE_BASE_DIR_PATH,PROJ_PROP_PREFIX + ANSIBLE_BASE_DIR_PATH);
65+
builder.frameworkMapping(ANSIBLE_BASE_DIR_PATH,FWK_PROP_PREFIX + ANSIBLE_BASE_DIR_PATH);
6366
builder.mapping(ANSIBLE_VAULT_PATH,PROJ_PROP_PREFIX + ANSIBLE_VAULT_PATH);
6467
builder.frameworkMapping(ANSIBLE_VAULT_PATH,FWK_PROP_PREFIX + ANSIBLE_VAULT_PATH);
6568
builder.mapping(ANSIBLE_VAULTSTORE_PATH,PROJ_PROP_PREFIX + ANSIBLE_VAULTSTORE_PATH);

src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleModuleWorkflowStep.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public class AnsibleModuleWorkflowStep implements StepPlugin, AnsibleDescribable
5252
builder.property(BECOME_USER_PROP);
5353
builder.property(BECOME_PASSWORD_STORAGE_PROP);
5454

55+
builder.mapping(ANSIBLE_BASE_DIR_PATH,PROJ_PROP_PREFIX + ANSIBLE_BASE_DIR_PATH);
56+
builder.frameworkMapping(ANSIBLE_BASE_DIR_PATH,FWK_PROP_PREFIX + ANSIBLE_BASE_DIR_PATH);
57+
5558
DESC = builder.build();
5659
}
5760

src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleNodeExecutor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class AnsibleNodeExecutor implements NodeExecutor, AnsibleDescribable, Pr
3535
builder.property(EXECUTABLE_PROP);
3636
builder.property(WINDOWS_EXECUTABLE_PROP);
3737
builder.property(CONFIG_FILE_PATH);
38+
builder.property(BASE_DIR_PROP);
3839
builder.property(GENERATE_INVENTORY_PROP);
3940
builder.property(GENERATE_INVENTORY_NODES_AUTH);
4041
builder.property(SSH_AUTH_TYPE_PROP);
@@ -62,6 +63,8 @@ public class AnsibleNodeExecutor implements NodeExecutor, AnsibleDescribable, Pr
6263
builder.frameworkMapping(ANSIBLE_WINDOWS_EXECUTABLE,FWK_PROP_PREFIX + ANSIBLE_WINDOWS_EXECUTABLE);
6364
builder.mapping(ANSIBLE_CONFIG_FILE_PATH,PROJ_PROP_PREFIX + ANSIBLE_CONFIG_FILE_PATH);
6465
builder.frameworkMapping(ANSIBLE_CONFIG_FILE_PATH,FWK_PROP_PREFIX + ANSIBLE_CONFIG_FILE_PATH);
66+
builder.mapping(ANSIBLE_BASE_DIR_PATH,PROJ_PROP_PREFIX + ANSIBLE_BASE_DIR_PATH);
67+
builder.frameworkMapping(ANSIBLE_BASE_DIR_PATH,FWK_PROP_PREFIX + ANSIBLE_BASE_DIR_PATH);
6568
builder.mapping(ANSIBLE_GENERATE_INVENTORY,PROJ_PROP_PREFIX + ANSIBLE_GENERATE_INVENTORY);
6669
builder.frameworkMapping(ANSIBLE_GENERATE_INVENTORY,FWK_PROP_PREFIX + ANSIBLE_GENERATE_INVENTORY);
6770
builder.mapping(ANSIBLE_GENERATE_INVENTORY_NODES_AUTH,PROJ_PROP_PREFIX + ANSIBLE_GENERATE_INVENTORY_NODES_AUTH);

src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsiblePlaybookInlineWorkflowNodeStep.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public class AnsiblePlaybookInlineWorkflowNodeStep implements NodeStepPlugin, An
6060
builder.property(BECOME_USER_PROP);
6161
builder.property(BECOME_PASSWORD_STORAGE_PROP);
6262

63+
builder.mapping(ANSIBLE_BASE_DIR_PATH,PROJ_PROP_PREFIX + ANSIBLE_BASE_DIR_PATH);
64+
builder.frameworkMapping(ANSIBLE_BASE_DIR_PATH,FWK_PROP_PREFIX + ANSIBLE_BASE_DIR_PATH);
65+
6366
DESC=builder.build();
6467
}
6568

src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsiblePlaybookInlineWorkflowStep.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ public class AnsiblePlaybookInlineWorkflowStep implements StepPlugin, AnsibleDes
6868
builder.property(BECOME_PASSWORD_STORAGE_PROP);
6969
builder.property(DISABLE_LIMIT_PROP);
7070

71+
builder.mapping(ANSIBLE_BASE_DIR_PATH,PROJ_PROP_PREFIX + ANSIBLE_BASE_DIR_PATH);
72+
builder.frameworkMapping(ANSIBLE_BASE_DIR_PATH,FWK_PROP_PREFIX + ANSIBLE_BASE_DIR_PATH);
73+
7174
DESC = builder.build();
7275
}
7376

src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsiblePlaybookWorflowNodeStep.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public class AnsiblePlaybookWorflowNodeStep implements NodeStepPlugin, AnsibleDe
5959
builder.property(BECOME_USER_PROP);
6060
builder.property(BECOME_PASSWORD_STORAGE_PROP);
6161

62+
builder.mapping(ANSIBLE_BASE_DIR_PATH,PROJ_PROP_PREFIX + ANSIBLE_BASE_DIR_PATH);
63+
builder.frameworkMapping(ANSIBLE_BASE_DIR_PATH,FWK_PROP_PREFIX + ANSIBLE_BASE_DIR_PATH);
64+
6265
DESC=builder.build();
6366
}
6467

src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsiblePlaybookWorkflowStep.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public class AnsiblePlaybookWorkflowStep implements StepPlugin, AnsibleDescribab
6666
builder.property(BECOME_PASSWORD_STORAGE_PROP);
6767
builder.property(DISABLE_LIMIT_PROP);
6868

69+
builder.mapping(ANSIBLE_BASE_DIR_PATH,PROJ_PROP_PREFIX + ANSIBLE_BASE_DIR_PATH);
70+
builder.frameworkMapping(ANSIBLE_BASE_DIR_PATH,FWK_PROP_PREFIX + ANSIBLE_BASE_DIR_PATH);
71+
6972
DESC = builder.build();
7073
}
7174

0 commit comments

Comments
 (0)