Class InventoryParser
java.lang.Object
com.scivicslab.actoriac.InventoryParser
Parser for Ansible inventory files in INI format.
This parser supports a subset of Ansible inventory file format. actor-IaC supports both Ansible-compatible syntax (ansible_*) and native syntax (actoriac_*).
Supported Features
- Groups:
[groupname] - Group variables:
[groupname:vars] - Global variables:
[all:vars] - Host-specific variables:
hostname key=value - Comments: lines starting with
#or;
Supported Variables
| actor-IaC | Ansible | Description |
|---|---|---|
| actoriac_host | ansible_host | Actual hostname/IP to connect |
| actoriac_user | ansible_user | SSH username |
| actoriac_port | ansible_port | SSH port |
| actoriac_connection | ansible_connection | Connection type (ssh/local) |
Unsupported Ansible Features
The following Ansible features are NOT supported and will generate warnings:
- Children groups:
[group:children] - Range patterns:
web[01:50].example.com - Privilege escalation:
ansible_become,ansible_become_user - Python interpreter:
ansible_python_interpreter
- Author:
- devteam@scivicslab.com
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a parsed Ansible inventory.static classResult of parsing an inventory file. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final PatternPattern to detect Ansible range notation like [01:50] or [a:z]Set of supported variable suffixes (without prefix)Set of known unsupported Ansible variables that should trigger warnings -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidChecks if a variable is unsupported and adds a warning if so.private static StringReturns a helpful suggestion for unsupported Ansible variables.static InventoryParser.ParseResultparse(InputStream input) Parses an Ansible inventory file.
-
Field Details
-
RANGE_PATTERN
Pattern to detect Ansible range notation like [01:50] or [a:z] -
SUPPORTED_VAR_SUFFIXES
Set of supported variable suffixes (without prefix) -
UNSUPPORTED_ANSIBLE_VARS
Set of known unsupported Ansible variables that should trigger warnings
-
-
Constructor Details
-
InventoryParser
public InventoryParser()
-
-
Method Details
-
parse
Parses an Ansible inventory file.This method collects warnings for unsupported Ansible features. Warnings are stored in the returned
InventoryParser.ParseResultand should be logged by the caller using the appropriate logging mechanism (e.g.,DistributedLogStore).- Parameters:
input- the input stream of the inventory file- Returns:
- the parse result containing inventory and any warnings
- Throws:
IOException- if reading the file fails
-
checkUnsupportedVariable
private static void checkUnsupportedVariable(String key, int lineNumber, Set<String> warnedVars, List<String> warnings) Checks if a variable is unsupported and adds a warning if so.- Parameters:
key- the variable namelineNumber- the line number for error reportingwarnedVars- set of already warned variables (to avoid duplicate warnings)warnings- list to add warnings to
-
getUnsupportedVarSuggestion
Returns a helpful suggestion for unsupported Ansible variables.
-