Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUN-1987: Ansible Playbook Inline Workflow step couldn't run in a node dispatched from a Remote Runner #344

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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'
}

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 @@ -110,15 +110,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
Loading