Skip to content

Commit

Permalink
Merge pull request #344 from rundeck-plugins/RUN-1987
Browse files Browse the repository at this point in the history
RUN-1987: use new ProxyRunnerPlugin interface to send data to the runner
  • Loading branch information
ltamaster committed Oct 25, 2023
2 parents 8bf314b + 17ea651 commit 6a2deef
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 129 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ configurations {

dependencies {
pluginLibs 'com.google.code.gson:gson:2.10.1'
implementation('org.rundeck:rundeck-core:4.16.0-rc1-20230815')
implementation('org.rundeck:rundeck-core:4.17.2-rc1-20231025')
implementation 'org.codehaus.groovy:groovy-all:3.0.9'

testImplementation platform("org.spockframework:spock-bom:2.0-groovy-3.0")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.rundeck.plugins.ansible.plugin;

import com.dtolabs.rundeck.core.execution.proxy.ProxySecretBundleCreator;
import com.dtolabs.rundeck.core.execution.proxy.SecretBundle;
import com.dtolabs.rundeck.core.execution.proxy.ProxyRunnerPlugin;
import com.rundeck.plugins.ansible.ansible.AnsibleDescribable;
import com.rundeck.plugins.ansible.ansible.AnsibleException.AnsibleFailureReason;
import com.rundeck.plugins.ansible.ansible.AnsibleRunner;
Expand All @@ -26,7 +25,7 @@
import java.util.Map;

@Plugin(name = AnsibleFileCopier.SERVICE_PROVIDER_NAME, service = ServiceNameConstants.FileCopier)
public class AnsibleFileCopier implements FileCopier, AnsibleDescribable, ProxySecretBundleCreator {
public class AnsibleFileCopier implements FileCopier, AnsibleDescribable, ProxyRunnerPlugin {

public static final String SERVICE_PROVIDER_NAME = "com.batix.rundeck.plugins.AnsibleFileCopier";

Expand Down Expand Up @@ -168,21 +167,6 @@ public Description getDescription() {
return DESC;
}

@Override
public SecretBundle prepareSecretBundle(ExecutionContext context, INodeEntry node) {
Map<String, Object> jobConf = new HashMap<>();
jobConf.put(AnsibleDescribable.ANSIBLE_LIMIT,node.getNodename());

if ("true".equals(System.getProperty("ansible.debug"))) {
jobConf.put(AnsibleDescribable.ANSIBLE_DEBUG,"True");
} else {
jobConf.put(AnsibleDescribable.ANSIBLE_DEBUG,"False");
}

AnsibleRunnerBuilder builder = new AnsibleRunnerBuilder(node, context, context.getFramework(), jobConf);
return AnsibleUtil.createBundle(builder);
}

@Override
public List<String> listSecretsPath(ExecutionContext context, INodeEntry node) {
Map<String, Object> jobConf = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.rundeck.plugins.ansible.plugin;

import com.dtolabs.rundeck.core.execution.proxy.ProxySecretBundleCreator;
import com.dtolabs.rundeck.core.execution.proxy.SecretBundle;
import com.dtolabs.rundeck.core.execution.proxy.ProxyRunnerPlugin;
import com.dtolabs.rundeck.core.plugins.configuration.ConfigurationException;
import com.rundeck.plugins.ansible.ansible.AnsibleDescribable;
import com.rundeck.plugins.ansible.ansible.AnsibleException;
Expand All @@ -24,7 +23,7 @@
import java.util.Map;

@Plugin(name = AnsibleNodeExecutor.SERVICE_PROVIDER_NAME, service = ServiceNameConstants.NodeExecutor)
public class AnsibleNodeExecutor implements NodeExecutor, AnsibleDescribable, ProxySecretBundleCreator {
public class AnsibleNodeExecutor implements NodeExecutor, AnsibleDescribable, ProxyRunnerPlugin {

public static final String SERVICE_PROVIDER_NAME = "com.batix.rundeck.plugins.AnsibleNodeExecutor";

Expand Down Expand Up @@ -190,21 +189,6 @@ public NodeExecutorResult executeCommand(ExecutionContext context, String[] comm
@Override
public Description getDescription() {
return DESC;
}

@Override
public SecretBundle prepareSecretBundle(ExecutionContext context, INodeEntry node) {
Map<String, Object> jobConf = new HashMap<>();
jobConf.put(AnsibleDescribable.ANSIBLE_LIMIT,node.getNodename());

if ("true".equals(System.getProperty("ansible.debug"))) {
jobConf.put(AnsibleDescribable.ANSIBLE_DEBUG,"True");
} else {
jobConf.put(AnsibleDescribable.ANSIBLE_DEBUG,"False");
}

AnsibleRunnerBuilder builder = new AnsibleRunnerBuilder(node, context, context.getFramework(), jobConf);
return AnsibleUtil.createBundle(builder);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.rundeck.plugins.ansible.plugin;

import com.dtolabs.rundeck.core.execution.ExecutionContext;
import com.dtolabs.rundeck.core.execution.proxy.ProxySecretBundleCreator;
import com.dtolabs.rundeck.core.execution.proxy.SecretBundle;
import com.dtolabs.rundeck.core.execution.proxy.ProxyRunnerPlugin;
import com.rundeck.plugins.ansible.ansible.AnsibleDescribable;
import com.rundeck.plugins.ansible.ansible.AnsibleException;
import com.rundeck.plugins.ansible.ansible.AnsibleRunner;
Expand All @@ -21,9 +20,10 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Plugin(name = AnsiblePlaybookInlineWorkflowNodeStep.SERVICE_PROVIDER_NAME, service = ServiceNameConstants.WorkflowNodeStep)
public class AnsiblePlaybookInlineWorkflowNodeStep implements NodeStepPlugin, AnsibleDescribable, ProxySecretBundleCreator {
public class AnsiblePlaybookInlineWorkflowNodeStep implements NodeStepPlugin, AnsibleDescribable, ProxyRunnerPlugin {

public static final String SERVICE_PROVIDER_NAME = "com.batix.rundeck.plugins.AnsiblePlaybookInlineWorkflowNodeStep";

Expand Down Expand Up @@ -109,15 +109,18 @@ public void executeNodeStep(
}

@Override
public SecretBundle prepareSecretBundleWorkflowNodeStep(ExecutionContext context, INodeEntry node, Map<String, Object> configuration) {
public List<String> listSecretsPathWorkflowNodeStep(ExecutionContext context, INodeEntry node, Map<String, Object> configuration) {
AnsibleRunnerBuilder builder = new AnsibleRunnerBuilder(node, context, context.getFramework(), configuration);
return AnsibleUtil.createBundle(builder);
return AnsibleUtil.getSecretsPath(builder);
}

@Override
public List<String> listSecretsPathWorkflowNodeStep(ExecutionContext context, INodeEntry node, Map<String, Object> configuration) {
AnsibleRunnerBuilder builder = new AnsibleRunnerBuilder(node, context, context.getFramework(), configuration);
return AnsibleUtil.getSecretsPath(builder);
public Map<String, String> getRuntimeProperties(ExecutionContext context) {
return AnsibleUtil.getRuntimeProperties(context, AnsibleDescribable.PROJ_PROP_PREFIX);
}

@Override
public Map<String, String> getRuntimeFrameworkProperties(ExecutionContext context) {
return AnsibleUtil.getRuntimeProperties(context, AnsibleDescribable.FWK_PROP_PREFIX);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.rundeck.plugins.ansible.plugin;

import com.dtolabs.rundeck.core.execution.ExecutionContext;
import com.dtolabs.rundeck.core.execution.proxy.ProxySecretBundleCreator;
import com.dtolabs.rundeck.core.execution.proxy.SecretBundle;
import com.dtolabs.rundeck.core.execution.proxy.ProxyRunnerPlugin;
import com.rundeck.plugins.ansible.ansible.AnsibleDescribable;
import com.rundeck.plugins.ansible.ansible.AnsibleException;
import com.rundeck.plugins.ansible.ansible.AnsibleRunner;
Expand All @@ -20,9 +19,10 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Plugin(name = AnsiblePlaybookInlineWorkflowStep.SERVICE_PROVIDER_NAME, service = ServiceNameConstants.WorkflowStep)
public class AnsiblePlaybookInlineWorkflowStep implements StepPlugin, AnsibleDescribable, ProxySecretBundleCreator {
public class AnsiblePlaybookInlineWorkflowStep implements StepPlugin, AnsibleDescribable, ProxyRunnerPlugin {

public static final String SERVICE_PROVIDER_NAME = "com.batix.rundeck.plugins.AnsiblePlaybookInlineWorkflowStep";

Expand Down Expand Up @@ -111,20 +111,27 @@ public void executeStep(PluginStepContext context, Map<String, Object> configura
builder.cleanupTempFiles();
}



@Override
public Description getDescription() {
return DESC;
}

@Override
public SecretBundle prepareSecretBundleWorkflowStep(ExecutionContext context, Map<String, Object> configuration) {
AnsibleRunnerBuilder builder = new AnsibleRunnerBuilder(context, context.getFramework(), context.getNodes(), configuration);
return AnsibleUtil.createBundle(builder);
}

@Override
public List<String> listSecretsPathWorkflowStep(ExecutionContext context, Map<String, Object> configuration) {
AnsibleRunnerBuilder builder = new AnsibleRunnerBuilder(context, context.getFramework(), context.getNodes(), configuration);
return AnsibleUtil.getSecretsPath(builder);
}

@Override
public Map<String, String> getRuntimeProperties(ExecutionContext context) {
return AnsibleUtil.getRuntimeProperties(context, AnsibleDescribable.PROJ_PROP_PREFIX);
}

@Override
public Map<String, String> getRuntimeFrameworkProperties(ExecutionContext context) {
return AnsibleUtil.getRuntimeProperties(context, AnsibleDescribable.FWK_PROP_PREFIX);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.rundeck.plugins.ansible.plugin;

import com.dtolabs.rundeck.core.execution.ExecutionContext;
import com.dtolabs.rundeck.core.execution.proxy.ProxySecretBundleCreator;
import com.dtolabs.rundeck.core.execution.proxy.SecretBundle;
import com.dtolabs.rundeck.core.execution.proxy.ProxyRunnerPlugin;
import com.rundeck.plugins.ansible.ansible.AnsibleDescribable;
import com.rundeck.plugins.ansible.ansible.AnsibleException;
import com.rundeck.plugins.ansible.ansible.AnsibleRunner;
Expand All @@ -20,9 +19,11 @@

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

@Plugin(name = AnsiblePlaybookWorflowNodeStep.SERVICE_PROVIDER_NAME, service = ServiceNameConstants.WorkflowNodeStep)
public class AnsiblePlaybookWorflowNodeStep implements NodeStepPlugin, AnsibleDescribable, ProxySecretBundleCreator {
public class AnsiblePlaybookWorflowNodeStep implements NodeStepPlugin, AnsibleDescribable, ProxyRunnerPlugin {

public static final String SERVICE_PROVIDER_NAME = "com.batix.rundeck.plugins.AnsiblePlaybookWorflowNodeStep";

Expand Down Expand Up @@ -100,14 +101,18 @@ public void executeNodeStep(
}

@Override
public SecretBundle prepareSecretBundleWorkflowNodeStep(ExecutionContext context, INodeEntry node, Map<String, Object> configuration) {
public List<String> listSecretsPathWorkflowNodeStep(ExecutionContext context, INodeEntry node, Map<String, Object> configuration) {
AnsibleRunnerBuilder builder = new AnsibleRunnerBuilder(node, context, context.getFramework(), configuration);
return AnsibleUtil.createBundle(builder);
return AnsibleUtil.getSecretsPath(builder);
}

@Override
public List<String> listSecretsPathWorkflowNodeStep(ExecutionContext context, INodeEntry node, Map<String, Object> configuration) {
AnsibleRunnerBuilder builder = new AnsibleRunnerBuilder(node, context, context.getFramework(), configuration);
return AnsibleUtil.getSecretsPath(builder);
public Map<String, String> getRuntimeProperties(ExecutionContext context) {
return AnsibleUtil.getRuntimeProperties(context, AnsibleDescribable.PROJ_PROP_PREFIX);
}

@Override
public Map<String, String> getRuntimeFrameworkProperties(ExecutionContext context) {
return AnsibleUtil.getRuntimeProperties(context, AnsibleDescribable.FWK_PROP_PREFIX);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.rundeck.plugins.ansible.plugin;

import com.dtolabs.rundeck.core.execution.ExecutionContext;
import com.dtolabs.rundeck.core.execution.proxy.ProxySecretBundleCreator;
import com.dtolabs.rundeck.core.execution.proxy.SecretBundle;
import com.dtolabs.rundeck.core.execution.proxy.ProxyRunnerPlugin;
import com.rundeck.plugins.ansible.ansible.AnsibleDescribable;
import com.rundeck.plugins.ansible.ansible.AnsibleException;
import com.rundeck.plugins.ansible.ansible.AnsibleRunner;
Expand All @@ -20,9 +19,10 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Plugin(name = AnsiblePlaybookWorkflowStep.SERVICE_PROVIDER_NAME, service = ServiceNameConstants.WorkflowStep)
public class AnsiblePlaybookWorkflowStep implements StepPlugin, AnsibleDescribable, ProxySecretBundleCreator {
public class AnsiblePlaybookWorkflowStep implements StepPlugin, AnsibleDescribable, ProxyRunnerPlugin {

public static final String SERVICE_PROVIDER_NAME = "com.batix.rundeck.plugins.AnsiblePlaybookWorkflowStep";

Expand Down Expand Up @@ -116,14 +116,17 @@ public Description getDescription() {
}

@Override
public SecretBundle prepareSecretBundleWorkflowStep(ExecutionContext context, Map<String, Object> configuration) {
public List<String> listSecretsPathWorkflowStep(ExecutionContext context, Map<String, Object> configuration) {
AnsibleRunnerBuilder builder = new AnsibleRunnerBuilder(context, context.getFramework(), context.getNodes(), configuration);
return AnsibleUtil.createBundle(builder);
return AnsibleUtil.getSecretsPath(builder);
}
@Override
public Map<String, String> getRuntimeProperties(ExecutionContext context) {
return AnsibleUtil.getRuntimeProperties(context, AnsibleDescribable.PROJ_PROP_PREFIX);
}

@Override
public List<String> listSecretsPathWorkflowStep(ExecutionContext context, Map<String, Object> configuration) {
AnsibleRunnerBuilder builder = new AnsibleRunnerBuilder(context, context.getFramework(), context.getNodes(), configuration);
return AnsibleUtil.getSecretsPath(builder);
public Map<String, String> getRuntimeFrameworkProperties(ExecutionContext context) {
return AnsibleUtil.getRuntimeProperties(context, AnsibleDescribable.FWK_PROP_PREFIX);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.rundeck.plugins.ansible.plugin;

import com.dtolabs.rundeck.core.execution.proxy.DefaultSecretBundle;
import com.dtolabs.rundeck.core.execution.proxy.ProxySecretBundleCreator;
import com.dtolabs.rundeck.core.execution.proxy.SecretBundle;
import com.dtolabs.rundeck.core.execution.proxy.ProxyRunnerPlugin;
import com.dtolabs.rundeck.core.storage.ResourceMeta;
import com.dtolabs.rundeck.core.storage.StorageTree;
import com.dtolabs.rundeck.core.storage.keys.KeyStorageTree;
Expand Down Expand Up @@ -38,7 +36,7 @@
import java.util.*;
import java.util.Map.Entry;

public class AnsibleResourceModelSource implements ResourceModelSource, ProxySecretBundleCreator {
public class AnsibleResourceModelSource implements ResourceModelSource, ProxyRunnerPlugin {

private Framework framework;

Expand Down Expand Up @@ -692,60 +690,4 @@ public List<String> listSecretsPathResourceModel(Map<String, Object> configurati

}

@Override
public SecretBundle prepareSecretBundleResourceModel(Services services, Map<String, Object> configuration){
DefaultSecretBundle secretBundle = new DefaultSecretBundle();

try {
StorageTree storageTree = services.getService(KeyStorageTree.class);

String passwordStoragePath = (String) configuration.get(AnsibleDescribable.ANSIBLE_SSH_PASSWORD_STORAGE_PATH);
String privateKeyStoragePath = (String) configuration.get(AnsibleDescribable.ANSIBLE_SSH_KEYPATH_STORAGE_PATH);
String passphraseStoragePath = (String) configuration.get(AnsibleDescribable.ANSIBLE_SSH_PASSPHRASE);
String vaultPasswordStoragePath = (String) configuration.get(AnsibleDescribable.ANSIBLE_VAULTSTORE_PATH);
String becamePasswordStoragePath = (String) configuration.get(AnsibleDescribable.ANSIBLE_BECOME_PASSWORD_STORAGE_PATH);

if(passwordStoragePath!=null && !passwordStoragePath.isEmpty()){
secretBundle.addSecret(
passwordStoragePath,
getStorageContent(passwordStoragePath,storageTree )
);
}

if(privateKeyStoragePath!=null && !privateKeyStoragePath.isEmpty()){
secretBundle.addSecret(
privateKeyStoragePath,
getStorageContent(privateKeyStoragePath,storageTree )
);
}

if(passphraseStoragePath!=null && !passphraseStoragePath.isEmpty()){
secretBundle.addSecret(
passphraseStoragePath,
getStorageContent(passphraseStoragePath,storageTree )
);
}

if(vaultPasswordStoragePath!=null && !vaultPasswordStoragePath.isEmpty()){
secretBundle.addSecret(
vaultPasswordStoragePath,
getStorageContent(vaultPasswordStoragePath,storageTree )
);
}

if(becamePasswordStoragePath!=null && !becamePasswordStoragePath.isEmpty()){
secretBundle.addSecret(
becamePasswordStoragePath,
getStorageContent(becamePasswordStoragePath,storageTree )
);
}

return secretBundle;

} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}


}
Loading

0 comments on commit 6a2deef

Please sign in to comment.