Skip to content

Commit 6a46aed

Browse files
committed
send private keys to runner
1 parent 684aa51 commit 6a46aed

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,10 @@ public int run() throws Exception {
541541
if(!hostPasswords.isEmpty()){
542542
procArgs.add("-e ansible_password=\"{{ host_passwords[inventory_hostname] }}\"");
543543
}
544-
procArgs.add("-e ansible_ssh_private_key_file=\"{{ host_private_keys[inventory_hostname] }}\"");
544+
545+
if(!hostKeys.isEmpty()){
546+
procArgs.add("-e ansible_ssh_private_key_file=\"{{ host_private_keys[inventory_hostname] }}\"");
547+
}
545548

546549
} catch (IOException e) {
547550
System.err.println("ERROR: Failed to write all.yaml: " + e.getMessage());

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,10 @@ public Map<String, Map<String, String>> getNodesAuthenticationMap(){
10471047

10481048
public List<String> getListNodesKeyPath(){
10491049

1050+
if(!generateInventoryNodesAuth()) {
1051+
return new ArrayList<>();
1052+
}
1053+
10501054
List<String> secretPaths = new ArrayList<>();
10511055

10521056
this.context.getNodes().forEach((node) -> {
@@ -1064,6 +1068,21 @@ public List<String> getListNodesKeyPath(){
10641068
secretPaths.add(keyPath);
10651069
}
10661070
}
1071+
1072+
String privateKeyPath = PropertyResolver.resolveProperty(
1073+
AnsibleDescribable.ANSIBLE_SSH_KEYPATH_STORAGE_PATH,
1074+
null,
1075+
getFrameworkProject(),
1076+
getFramework(),
1077+
node,
1078+
getJobConf()
1079+
);
1080+
1081+
if(null!=privateKeyPath){
1082+
if(!secretPaths.contains(privateKeyPath)){
1083+
secretPaths.add(privateKeyPath);
1084+
}
1085+
}
10671086
});
10681087

10691088
return secretPaths;

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,7 @@ public List<String> listSecretsPath(ExecutionContext context, INodeEntry node) {
200200
jobConf.put(AnsibleDescribable.ANSIBLE_LIMIT,node.getNodename());
201201
AnsibleRunnerContextBuilder builder = new AnsibleRunnerContextBuilder(node, context, context.getFramework(), jobConf);
202202

203-
List<String> secretPaths = AnsibleUtil.getSecretsPath(builder);
204-
List<String> secretPathsNodes = builder.getListNodesKeyPath();
205-
206-
if(secretPathsNodes != null && !secretPathsNodes.isEmpty()){
207-
secretPaths.addAll(secretPathsNodes);
208-
}
209-
return secretPaths;
203+
return AnsibleUtil.getSecretsPath(builder);
210204
}
211205
}
212206

0 commit comments

Comments
 (0)