Class NodeGroup
This is a pure POJO class that reads Ansible inventory files and creates Node objects for a specific group. It does not depend on ActorSystem - the responsibility of converting Node objects to actors belongs to the caller.
SSH authentication is handled by ssh-agent. Make sure ssh-agent is running and your SSH key is added before creating nodes.
Usage Examples
Using Builder Pattern (Recommended)
NodeGroup nodeGroup = new NodeGroup.Builder()
.withInventory(new FileInputStream("inventory.ini"))
.build();
Legacy Constructor Pattern
NodeGroup nodeGroup = new NodeGroup();
nodeGroup.loadInventory(new FileInputStream("inventory.ini"));
- Since:
- 1.0
- Author:
- devteam@scivicslab.com
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating NodeGroup instances with fluent API. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates a single Node for localhost execution.createNodesForGroup(String groupName) Creates Node objects for all hosts in the specified group.Gets the host limit.Gets the inventory object.Gets the warnings generated during inventory parsing.Gets the SSH password.booleanChecks if there are any parse warnings.voidloadInventory(InputStream inventoryStream) Loads an inventory file from an input stream.voidsetHostLimit(String limitString) Sets the host limit to restrict execution to specific hosts.voidsetSshPassword(String password) Sets the SSH password for all nodes in this group.toString()Returns a string representation of this NodeGroup, including the loaded group names.
-
Constructor Details
-
NodeGroup
public NodeGroup()Constructs an empty NodeGroup.Note: Consider using
NodeGroup.Builderfor a more fluent API.
-
-
Method Details
-
loadInventory
Loads an inventory file from an input stream.Any warnings generated during parsing are stored and can be retrieved via
getParseWarnings().- Parameters:
inventoryStream- the input stream containing the inventory file- Throws:
IOException- if reading the inventory fails
-
getParseWarnings
Gets the warnings generated during inventory parsing.These warnings should be logged by the caller using the appropriate logging mechanism.
- Returns:
- list of warning messages (may be empty)
-
hasParseWarnings
public boolean hasParseWarnings()Checks if there are any parse warnings.- Returns:
- true if there are warnings
-
createNodesForGroup
Creates Node objects for all hosts in the specified group.This method reads the group from the inventory, applies global and group-specific variables, and creates a Node POJO for each host.
Note: This method returns plain Node objects, not actors. The caller is responsible for converting them to actors using ActorSystem.actorOf() if needed.
- Parameters:
groupName- the name of the group from the inventory file- Returns:
- the list of created Node objects
- Throws:
IllegalStateException- if inventory has not been loaded
-
createLocalNode
Creates a single Node for localhost execution.This method creates a Node configured for local execution without requiring an inventory file.
- Returns:
- a list containing a single localhost Node
-
getInventory
Gets the inventory object.- Returns:
- the loaded inventory, or null if not loaded
-
setSshPassword
Sets the SSH password for all nodes in this group.- Parameters:
password- the SSH password to use for all nodes
-
getSshPassword
Gets the SSH password.- Returns:
- the SSH password, or null if not set
-
setHostLimit
Sets the host limit to restrict execution to specific hosts.- Parameters:
limitString- comma-separated list of hosts
-
getHostLimit
Gets the host limit.- Returns:
- the list of limited hosts, or null if no limit is set
-
toString
Returns a string representation of this NodeGroup, including the loaded group names.
-