rundeck-plugins / salt-step

Rundeck Salt Plugin
BSD 3-Clause "New" or "Revised" License
31 stars 30 forks source link

Unable to run salt modules/functions from rundeck using salt step #15

Closed ghost closed 8 years ago

ghost commented 8 years ago

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.

ghost commented 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;

/**

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: