Closed ghost closed 8 years ago
Found the fix myself.
The problem with salt modules and functions like test.ping return a boolean value like TRUE or FALSE.
org.rundeck.plugin.salt.output.SaltReturnResponse expects the return value to be a json response from salt api.
To add the boolean value, one needs to modify the code located at /src/main/java/org/rundeck/plugin/salt/output/SaltJsonReturnHandler.java
/**
package org.rundeck.plugin.salt.output;
import java.lang.reflect.Type; import java.util.Map;
import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken;
/**
Handler for generating {@link SaltReturnResponse} from minion json responses. */ public class SaltJsonReturnHandler implements SaltReturnHandler {
protected static final Type RETURN_RESPONSE_TYPE = new TypeToken<Map<String, String>>() {}.getType();
protected String exitCodeKey; protected String standardOutputKey; protected String standardErrorKey;
public void setExitCodeKey(String exitCodeKey) { this.exitCodeKey = exitCodeKey; }
public void setStandardOutputKey(String standardOutputKey) { this.standardOutputKey = standardOutputKey; }
public void setStandardErrorKey(String standardErrorKey) { this.standardErrorKey = standardErrorKey; }
@Override public String toString() { return "SaltJsonReturnHandler [exitCodeKey=" + exitCodeKey + ", standardOutputKey=" + standardOutputKey
/**
if there was an error interpreting the response
*/ @Override public SaltReturnResponse extractResponse(String rawResponse) throws SaltReturnResponseParseException { try { Gson gson = new Gson(); Map<String, String> result = gson.fromJson(rawResponse, RETURN_RESPONSE_TYPE); SaltReturnResponse response = new SaltReturnResponse();
if (exitCodeKey != null) {
String exitCodeStringValue = extractOrDie(exitCodeKey, result);
Integer exitCode = Double.valueOf(exitCodeStringValue).intValue();
response.setExitCode(exitCode);
}
if (standardOutputKey != null) {
String output = extractOrDie(standardOutputKey, result);
response.addOutput(output);
}
if (standardErrorKey != null) {
String error = extractOrDie(standardErrorKey, result);
response.addError(error);
}
return response;
} catch (JsonSyntaxException e) { throw new SaltReturnResponseParseException(e); } }
protected String extractOrDie(String key, Map<String, String> data) throws SaltReturnResponseParseException { if (!data.containsKey(key)) { throw new SaltReturnResponseParseException(String.format("Expected key %s in %s, found none.", key, data)); } else { return data.get(key); } } }
In the above code, Gson object should be able to evaluate RETURN_RESPONSE_TYPE as boolean as shown below:
Map<String, String> result = gson.fromJson(rawResponse, RETURN_RESPONSE_TYPE);
I have decided to write my custom module and function in salt so that it returns the json response to rundeck salt step plugin instead of modifying the Gson code because i need to differentiate between command executed from rundeck is either a cmd.run_all or a salt module Example : test.ping
Thanks to all who had a look at this issue and walked over it :+1:
Hi
I am able to run only cmd.run_all module/function salt commands from rundeck using salt step plugin.
I am aware that the cmd.run_all function is present in:
/build/resources/main/defaultReturners.yaml:
handlerMappings: cmd.run_all: defaultCommandParser state.highstate: alwaysSuccessful file.touch: alwaysSuccessful file.append: alwaysSuccessful file.remove: *alwaysSuccessful
Could anyone please tell me how can i run all the salt commands like for example : "test.ping" or "pkg.install"
I am not able to find any documentation about salt-step plugin usage with salt-api and salt.