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"));
- Author:
- devteam@scivics-lab.com
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating NodeGroup instances with fluent API. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructs an empty NodeGroup.privateNodeGroup(InventoryParser.Inventory inventory) Private constructor used by Builder. -
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 SSH password.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()
-
Field Details
-
inventory
-
sshPassword
-
hostLimit
-
-
Constructor Details
-
NodeGroup
public NodeGroup()Constructs an empty NodeGroup.Note: Consider using
NodeGroup.Builderfor a more fluent API. -
NodeGroup
Private constructor used by Builder.- Parameters:
inventory- the parsed inventory
-
-
Method Details
-
loadInventory
Loads an inventory file from an input stream.- Parameters:
inventoryStream- the input stream containing the inventory file- Throws:
IOException- if reading the inventory fails
-
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.
If Vault integration is configured, this method will fetch SSH keys and sudo passwords from Vault based on the vault-config.ini settings.
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 loadedRuntimeException- if Vault secret retrieval fails
-
createLocalNode
Creates a single Node for localhost execution.This method creates a Node configured for local execution without requiring an inventory file. Useful for development, testing, or single-host scenarios.
The node is created with:
- hostname: "localhost"
- user: current system user
- localMode: true (uses ProcessBuilder instead of SSH)
- 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.When set, nodes will use password authentication instead of ssh-agent key authentication.
- Parameters:
password- the SSH password to use for all nodes
-
getSshPassword
-
setHostLimit
Sets the host limit to restrict execution to specific hosts.When set, only hosts in this list will be included when creating nodes. This is similar to Ansible's --limit option.
- Parameters:
limitString- comma-separated list of hosts (e.g., "192.168.5.15,192.168.5.16")
-
getHostLimit
Gets the host limit.- Returns:
- the list of limited hosts, or null if no limit is set
-
toString
-