Skip to content

Commit

Permalink
Merge pull request #347 from rundeck-plugins/RUN-2130
Browse files Browse the repository at this point in the history
RUN-2130: print an error if the node doesn't have a hostname in generate inventory
  • Loading branch information
ltamaster authored Jan 10, 2024
2 parents 92eff5c + dfb0d85 commit 5b1dad9
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.dtolabs.rundeck.core.plugins.configuration.ConfigurationException;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -25,12 +26,15 @@ public File buildInventory() throws ConfigurationException {
PrintWriter writer = new PrintWriter(file);
AnsibleInventory ai = new AnsibleInventory();
for (INodeEntry e : nodes) {
if( e.getHostname() == null ){
throw new ConfigurationException("No hostname for node: " + e.getNodename());
}
ai.addHost(e.getNodename(), e.getHostname(), new HashMap<String, String>(e.getAttributes()));
}
writer.write(new Gson().toJson(ai));
writer.close();
return file;
} catch (Exception e) {
} catch (IOException e) {
throw new ConfigurationException("Could not write temporary inventory: " + e.getMessage());
}
}
Expand Down

0 comments on commit 5b1dad9

Please sign in to comment.