@@ -465,8 +465,8 @@ public int run() throws Exception {
465465 try {
466466 // Sanitize node name for filesystem use
467467 String safeNodeName = sanitizeNodeNameForFilesystem (nodeName );
468- if (debug && !nodeName .equals (safeNodeName )) {
469- System . err . println ( "DEBUG: Sanitized node name '" + nodeName + " ' to '" + safeNodeName + " ' for temp file" );
468+ if (!nodeName .equals (safeNodeName )) {
469+ log . debug ( " Sanitized node name '{} ' to '{} ' for temp file", nodeName , safeNodeName );
470470 }
471471 tempHostPkFile = AnsibleUtil .createTemporaryFile ("" ,"id_rsa_node_" +safeNodeName , privateKey ,customTmpDirPath );
472472
@@ -489,10 +489,8 @@ public int run() throws Exception {
489489 // Build YAML content using helper method
490490 String yamlContent = buildGroupVarsYaml (hostPasswords , hostUsers , hostKeys );
491491
492- if (debug ){
493- System .err .println ("DEBUG: Building group_vars YAML with " + hostPasswords .size () + " passwords, " + hostUsers .size () + " users, and " + hostKeys .size () + " private keys" );
494- System .err .println ("DEBUG: YAML content built successfully, length: " + yamlContent .length ());
495- }
492+ log .debug ("Building group_vars YAML with {} passwords, {} users, and {} private keys" , hostPasswords .size (), hostUsers .size (), hostKeys .size ());
493+ log .debug ("YAML content built successfully, length: {}" , yamlContent .length ());
496494
497495 try {
498496
@@ -505,17 +503,13 @@ public int run() throws Exception {
505503 File inventoryFile = new File (inventory );
506504 File inventoryParentDir = inventoryFile .getParentFile ();
507505
508- if (debug ) {
509- System .err .println ("DEBUG: inventoryFile: " + inventoryFile .getAbsolutePath ());
510- System .err .println ("DEBUG: inventory file exists: " + inventoryFile .exists ());
511- System .err .println ("DEBUG: inventoryParentDir: " + (inventoryParentDir != null ? inventoryParentDir .getAbsolutePath () : "null" ));
512- }
506+ log .debug ("inventoryFile: {}" , inventoryFile .getAbsolutePath ());
507+ log .debug ("inventory file exists: {}" , inventoryFile .exists ());
508+ log .debug ("inventoryParentDir: {}" , (inventoryParentDir != null ? inventoryParentDir .getAbsolutePath () : "null" ));
513509
514510 if (inventoryParentDir != null ) {
515511 groupVarsDir = new File (inventoryParentDir , "group_vars" );
516- if (debug ) {
517- System .err .println ("DEBUG: group_vars directory path: " + groupVarsDir .getAbsolutePath ());
518- }
512+ log .debug ("group_vars directory path: {}" , groupVarsDir .getAbsolutePath ());
519513
520514 try {
521515 // Use Files.createDirectories() which is idempotent (safe to call if directory exists)
@@ -540,25 +534,19 @@ public int run() throws Exception {
540534 "This file will be cleaned up after execution, but may persist if cleanup fails." ,
541535 tempNodeAuthFile .getAbsolutePath ());
542536
543- if (debug ) {
544- System .err .println ("DEBUG: Writing all.yaml to: " + tempNodeAuthFile .getAbsolutePath ());
545- System .err .println ("DEBUG: all.yaml written successfully, file size: " + tempNodeAuthFile .length () + " bytes" );
546- }
537+ log .debug ("Writing all.yaml to: {}" , tempNodeAuthFile .getAbsolutePath ());
538+ log .debug ("all.yaml written successfully, file size: {} bytes" , tempNodeAuthFile .length ());
547539 } else {
548540 // Fallback to temp file if inventory has no parent directory
549541 tempNodeAuthFile = AnsibleUtil .createTemporaryFile ("group_vars" , "all.yaml" , yamlContent , customTmpDirPath );
550542
551- if (debug ) {
552- System .err .println ("DEBUG: No parent directory, using temporary file" );
553- System .err .println ("DEBUG: Temporary all.yaml created at: " + tempNodeAuthFile .getAbsolutePath ());
554- }
543+ log .debug ("No parent directory, using temporary file" );
544+ log .debug ("Temporary all.yaml created at: {}" , tempNodeAuthFile .getAbsolutePath ());
555545 }
556546
557- if (debug ) {
558- System .err .println ("DEBUG: tempNodeAuthFile: " + tempNodeAuthFile .getAbsolutePath ());
559- System .err .println ("DEBUG: tempNodeAuthFile exists: " + tempNodeAuthFile .exists ());
560- System .err .println ("DEBUG: tempNodeAuthFile readable: " + tempNodeAuthFile .canRead ());
561- }
547+ log .debug ("tempNodeAuthFile: {}" , tempNodeAuthFile .getAbsolutePath ());
548+ log .debug ("tempNodeAuthFile exists: {}" , tempNodeAuthFile .exists ());
549+ log .debug ("tempNodeAuthFile readable: {}" , tempNodeAuthFile .canRead ());
562550
563551 //set extra vars to resolve the host specific authentication
564552 if (!hostUsers .isEmpty ()) {
@@ -1011,7 +999,7 @@ String buildGroupVarsYaml(Map<String, String> hostPasswords, Map<String, String>
1011999
10121000 // Validate vault format
10131001 if (!isValidVaultFormat (vaultValue )) {
1014- System . err . println ( "ERROR: Invalid vault format for host: " + originalKey );
1002+ log . error ( " Invalid vault format for host: {}" , originalKey );
10151003 throw new RuntimeException ("Invalid vault format for host: " + originalKey );
10161004 }
10171005 // The vault value already contains "!vault |\n" followed by the encrypted content
@@ -1047,9 +1035,7 @@ String buildGroupVarsYaml(Map<String, String> hostPasswords, Map<String, String>
10471035
10481036 String result = yamlContent .toString ();
10491037
1050- if (debug ){
1051- System .err .println ("DEBUG: Generated YAML content (" + result .length () + " bytes)" );
1052- }
1038+ log .debug ("Generated YAML content ({} bytes)" , result .length ());
10531039
10541040 return result ;
10551041 }
0 commit comments