44import com .dtolabs .rundeck .core .common .IRundeckProject ;
55import com .dtolabs .rundeck .core .common .ProjectManager ;
66import com .dtolabs .rundeck .core .execution .ExecutionContext ;
7+ import com .dtolabs .rundeck .plugins .PluginLogger ;
78import com .dtolabs .rundeck .core .execution .service .NodeExecutor ;
89import com .dtolabs .rundeck .core .execution .service .NodeExecutorResult ;
910import com .dtolabs .rundeck .core .execution .service .NodeExecutorResultImpl ;
@@ -23,6 +24,7 @@ public class AnsibleNodeExecutor implements NodeExecutor, Describable {
2324
2425 @ Override
2526 public NodeExecutorResult executeCommand (ExecutionContext context , String [] command , INodeEntry node ) {
27+
2628 StringBuilder cmdArgs = new StringBuilder ();
2729 ProjectManager projectManager = context .getFramework ().getProjectManager ();
2830 IRundeckProject project = projectManager .getFrameworkProject (context .getFrameworkProject ());
@@ -35,37 +37,18 @@ public NodeExecutorResult executeCommand(ExecutionContext context, String[] comm
3537 String extraArgs = project .hasProperty ("extraArgs" ) ? project .getProperty ("extraArgs" ) : null ;
3638
3739 AnsibleRunner runner = AnsibleRunner .adHoc ("shell" , cmdArgs .toString ()).limit (node .getNodename ()).extraArgs (extraArgs );
40+
3841 if ("true" .equals (System .getProperty ("ansible.debug" ))) {
3942 runner .debug ();
4043 }
44+
4145 int result ;
4246 try {
4347 result = runner .run ();
4448 } catch (Exception e ) {
45- System .out .println (e .getMessage ());
46- e .printStackTrace ();
4749 return NodeExecutorResultImpl .createFailure (AnsibleFailureReason .AnsibleError , e .getMessage (), e , node , runner .getResult ());
4850 }
4951
50- JsonObject json = runner .getResults ().get (0 ).results .size () > 0 ? runner .getResults ().get (0 ).results .get (0 ).json : null ;
51-
52- if (json != null && json .has ("stdout" )) {
53- String string = json .get ("stdout" ).getAsString ();
54- if (string != null && string .length () > 0 ) {
55- System .out .println (string );
56- }
57- }
58- if (json != null && json .has ("stderr" )) {
59- String string = json .get ("stderr" ).getAsString ();
60- if (string != null && string .length () > 0 ) {
61- System .err .println (string );
62- }
63- }
64-
65- if (result != 0 ) {
66- return NodeExecutorResultImpl .createFailure (AnsibleFailureReason .AnsibleNonZero , "Ansible exited with non-zero code." , node , result );
67- }
68-
6952 return NodeExecutorResultImpl .createSuccess (node );
7053 }
7154
0 commit comments