Documentation
¶
Index ¶
- Constants
- Variables
- func FindProjects(fsys fs.FS, root string) ([]string, error)
- type AnsibleConfig
- type AnsibleProject
- type GalaxyManifest
- type Mapping
- type Module
- type Node
- func (n *Node) AsBool() (bool, bool)
- func (n *Node) AsString() (string, bool)
- func (n *Node) BoolValue(path string) iacTypes.BoolValue
- func (n *Node) IsBool() bool
- func (n *Node) IsKnown() bool
- func (n *Node) IsList() bool
- func (n *Node) IsMap() bool
- func (n *Node) IsNil() bool
- func (n *Node) IsString() bool
- func (n *Node) MarshalYAML() (any, error)
- func (n *Node) Metadata() iacTypes.Metadata
- func (n *Node) NodeAt(path string) *Node
- func (n *Node) Render(variables vars.Vars) (*Node, error)
- func (n *Node) StringValue(path string) iacTypes.StringValue
- func (n *Node) Subtree(r Range) *Node
- func (n *Node) ToList() []*Node
- func (n *Node) ToMap() map[string]*Node
- func (n *Node) UnmarshalYAML(node *yaml.Node) error
- func (n *Node) Value() any
- type NodeValue
- type Option
- type Parser
- type Play
- type Playbook
- type Range
- type ResolvedTask
- type ResolvedTasks
- type Role
- type RoleDefinition
- type RoleIncludeModule
- type RoleMeta
- type Scalar
- type Sequence
- type Task
Constants ¶
const ( ModuleIncludeRole = "include_role" ModuleImportRole = "import_role" ModuleIncludeTasks = "include_tasks" ModuleImportTasks = "import_tasks" )
const ( NullTag = "!!null" StrTag = "!!str" )
Variables ¶
var ErrModuleNotFound = errors.New("module not found")
Functions ¶
func FindProjects ¶
FindProjects locates Ansible project roots within fsys starting from root. A directory is recognized as a project root if it contains key files or directories like ansible.cfg, inventory, group_vars, host_vars, roles, playbooks, or YAML playbooks.
Returns a slice of project root paths.
Types ¶
type AnsibleConfig ¶
type AnsibleConfig struct {
Inventory string
}
func LoadConfig ¶
func LoadConfig(fsys fs.FS, dir string) (AnsibleConfig, error)
type AnsibleProject ¶
type AnsibleProject struct {
// contains filtered or unexported fields
}
func ParseProject ¶
func (*AnsibleProject) ListTasks ¶
func (p *AnsibleProject) ListTasks() ResolvedTasks
TODO(nikita): some tasks do not contain metadata
func (*AnsibleProject) Path ¶
func (p *AnsibleProject) Path() string
type GalaxyManifest ¶
type Mapping ¶
type Mapping struct {
Fields *orderedmap.OrderedMap[string, *Node]
}
func (*Mapping) MarshalYAML ¶
type Module ¶
Module represents a logical module in a playbook or task. It wraps a Node and provides module-specific utility methods.
All the data and metadata for the module is stored in the embedded Node.
func (*Module) IsFreeForm ¶
IsFreeForm returns true if the module is a free-form Ansible module. In Ansible, a free-form module is called using a single scalar value instead of a key-value mapping.
Example:
# Free-form
- command: echo "Hello"
# IsFreeForm() -> true
# Structured
- ansible.builtin.yum:
name: vim
state: present
# IsFreeForm() -> false
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func (*Node) MarshalYAML ¶
func (*Node) StringValue ¶
func (n *Node) StringValue(path string) iacTypes.StringValue
type Option ¶
type Option func(p *Parser)
func WithExtraVars ¶
func WithInventories ¶
func WithPlaybooks ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func (*Parser) Parse ¶
func (p *Parser) Parse() (*AnsibleProject, error)
type Play ¶
type Play struct {
// contains filtered or unexported fields
}
Play represents a single play in an Ansible playbook.
An Ansible playbook is a list of such plays, where each play defines settings and tasks for a specific group of hosts.
Example playbook YAML:
- name: My first play hosts: myhosts tasks:
- name: Ping my hosts ping:
This play contains a name, target hosts, and a list of tasks.
type Playbook ¶
type Playbook struct {
Src fsutils.FileSource
Plays []*Play
Tasks []*Task
}
Playbook represents a sequence of plays in an Ansible playbook.
A playbook is typically loaded from a YAML file and contains a list of plays that are executed in order.
The playbook corresponds to a YAML list, for example:
name: First play hosts: all tasks:
...
name: Second play hosts: dbservers tasks:
...
type ResolvedTask ¶
type ResolvedTask struct {
Name string
Fields orderedmap.OrderedMap[string, *Node]
Vars vars.Vars
Metadata iacTypes.Metadata
Range Range
}
ResolvedTask represents an Ansible task with all variables resolved.
It holds only the essential data needed for execution and ensures the original Task remains unmodified.
func (*ResolvedTask) GetFieldsByRange ¶
func (t *ResolvedTask) GetFieldsByRange(r Range) map[string]*Node
func (*ResolvedTask) MarshalYAML ¶
func (t *ResolvedTask) MarshalYAML() (any, error)
func (*ResolvedTask) ResolveModule ¶
func (t *ResolvedTask) ResolveModule(keys []string, strict bool) (Module, error)
ResolveModule searches for the first module from given keys in task fields, renders its parameters using task variables, and returns the module. The module can be either structured (map of parameters) or free-form (string). Returns an error if no module is found or if rendering fails.
type ResolvedTasks ¶
type ResolvedTasks []*ResolvedTask
func (ResolvedTasks) FilterByState ¶
func (t ResolvedTasks) FilterByState(exclude ...string) ResolvedTasks
func (ResolvedTasks) GetModules ¶
func (t ResolvedTasks) GetModules(keys ...string) []Module
type Role ¶
type Role struct {
// contains filtered or unexported fields
}
Role represent project role
type RoleDefinition ¶
type RoleDefinition struct {
// contains filtered or unexported fields
}
RoleDefinition represents a role reference within a play.
It typically contains the role name and optional parameters that customize how the role is applied.
Example usage in a playbook:
roles:
- common
- role: webserver
vars:
http_port: 80
func (*RoleDefinition) UnmarshalYAML ¶
func (r *RoleDefinition) UnmarshalYAML(node *yaml.Node) error
type RoleIncludeModule ¶
RoleIncludeModule represents the "include_role" or "import_role" module
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task represents a single Ansible task.
A task defines a single unit of work, which may include running a module, calling a role, or including other task files.
Tasks can contain parameters, conditions (when), loops, and other Ansible constructs.
Example task:
- name: Install nginx apt: name: nginx state: present