@@ -351,6 +351,7 @@ public int run() throws Exception {
351351 List <String > procArgs = new ArrayList <>();
352352 Process proc = null ;
353353
354+ final boolean isAdHoc = (type == AnsibleCommand .AdHoc );
354355 try {
355356
356357 String ansibleCommand = type .command ;
@@ -360,7 +361,7 @@ public int run() throws Exception {
360361 procArgs .add (ansibleCommand );
361362
362363 // parse arguments
363- if (type == AnsibleCommand . AdHoc ) {
364+ if (isAdHoc ) {
364365 procArgs .add ("all" );
365366
366367 procArgs .add ("-m" );
@@ -512,13 +513,7 @@ public int run() throws Exception {
512513 //SET env variables
513514 Map <String , String > processEnvironment = new HashMap <>();
514515
515- if (type == AnsibleCommand .AdHoc ){
516- processEnvironment .put ("ANSIBLE_LOAD_CALLBACK_PLUGINS" , "1" );
517- processEnvironment .put ("ANSIBLE_CALLBACKS_ENABLED" , "ansible.builtin.tree" );
518- if (baseDirectory != null ) {
519- processEnvironment .put ("ANSIBLE_CALLBACK_TREE_DIR" , baseDirectory .toFile ().getAbsolutePath ());
520- }
521- }
516+
522517
523518 if (configFile != null && !configFile .isEmpty ()) {
524519 if (debug ) {
@@ -531,6 +526,13 @@ public int run() throws Exception {
531526 for (String optionName : this .options .keySet ()) {
532527 processEnvironment .put (optionName , this .options .get (optionName ));
533528 }
529+ if (isAdHoc ) {
530+ processEnvironment .putIfAbsent ("ANSIBLE_LOAD_CALLBACK_PLUGINS" , "1" );
531+ processEnvironment .putIfAbsent ("ANSIBLE_CALLBACKS_ENABLED" , "ansible.builtin.tree" );
532+ if (baseDirectory != null ) {
533+ processEnvironment .putIfAbsent ("ANSIBLE_CALLBACK_TREE_DIR" , baseDirectory .toFile ().getAbsolutePath ());
534+ }
535+ }
534536
535537 if (sshUseAgent && sshAgent != null ) {
536538 processEnvironment .put ("SSH_AUTH_SOCK" , this .sshAgent .getSocketPath ());
0 commit comments