Documentation
¶
Index ¶
- Variables
- func GetHostVars(inv *Inventory, hostname string) map[string]any
- func GetHosts(inv *Inventory, pattern string) []string
- func NormalizeModule(name string) string
- type Executor
- func (e *Executor) Close()
- func (e *Executor) Run(ctx context.Context, playbookPath string) error
- func (e *Executor) SetInventory(path string) error
- func (e *Executor) SetInventoryDirect(inv *Inventory)
- func (e *Executor) SetVar(key string, value any)
- func (e *Executor) TemplateFile(src, host string, task *Task) (string, error)
- type Facts
- type Host
- type Inventory
- type InventoryGroup
- type LoopControl
- type Parser
- type Play
- type Playbook
- type RoleRef
- type SSHClient
- func (c *SSHClient) Close() error
- func (c *SSHClient) Connect(ctx context.Context) error
- func (c *SSHClient) Download(ctx context.Context, remote string) ([]byte, error)
- func (c *SSHClient) FileExists(ctx context.Context, path string) (bool, error)
- func (c *SSHClient) Run(ctx context.Context, cmd string) (stdout, stderr string, exitCode int, err error)
- func (c *SSHClient) RunScript(ctx context.Context, script string) (stdout, stderr string, exitCode int, err error)
- func (c *SSHClient) SetBecome(become bool, user, password string)
- func (c *SSHClient) Stat(ctx context.Context, path string) (map[string]any, error)
- func (c *SSHClient) Upload(ctx context.Context, local io.Reader, remote string, mode os.FileMode) error
- type SSHConfig
- type Task
- type TaskResult
Constants ¶
This section is empty.
Variables ¶
var KnownModules = []string{
"ansible.builtin.shell",
"ansible.builtin.command",
"ansible.builtin.raw",
"ansible.builtin.script",
"ansible.builtin.copy",
"ansible.builtin.template",
"ansible.builtin.file",
"ansible.builtin.lineinfile",
"ansible.builtin.blockinfile",
"ansible.builtin.stat",
"ansible.builtin.slurp",
"ansible.builtin.fetch",
"ansible.builtin.get_url",
"ansible.builtin.uri",
"ansible.builtin.apt",
"ansible.builtin.apt_key",
"ansible.builtin.apt_repository",
"ansible.builtin.yum",
"ansible.builtin.dnf",
"ansible.builtin.package",
"ansible.builtin.pip",
"ansible.builtin.service",
"ansible.builtin.systemd",
"ansible.builtin.user",
"ansible.builtin.group",
"ansible.builtin.cron",
"ansible.builtin.git",
"ansible.builtin.unarchive",
"ansible.builtin.archive",
"ansible.builtin.debug",
"ansible.builtin.fail",
"ansible.builtin.assert",
"ansible.builtin.pause",
"ansible.builtin.wait_for",
"ansible.builtin.set_fact",
"ansible.builtin.include_vars",
"ansible.builtin.add_host",
"ansible.builtin.group_by",
"ansible.builtin.meta",
"ansible.builtin.setup",
"shell",
"command",
"raw",
"script",
"copy",
"template",
"file",
"lineinfile",
"blockinfile",
"stat",
"slurp",
"fetch",
"get_url",
"uri",
"apt",
"apt_key",
"apt_repository",
"yum",
"dnf",
"package",
"pip",
"service",
"systemd",
"user",
"group",
"cron",
"git",
"unarchive",
"archive",
"debug",
"fail",
"assert",
"pause",
"wait_for",
"set_fact",
"include_vars",
"add_host",
"group_by",
"meta",
"setup",
}
Known Ansible modules
Functions ¶
func GetHostVars ¶
GetHostVars returns variables for a specific host.
func NormalizeModule ¶
NormalizeModule normalizes a module name to its canonical form.
Types ¶
type Executor ¶
type Executor struct {
// Callbacks
OnPlayStart func(play *Play)
OnTaskStart func(host string, task *Task)
OnTaskEnd func(host string, task *Task, result *TaskResult)
OnPlayEnd func(play *Play)
// Options
Limit string
Tags []string
SkipTags []string
CheckMode bool
Diff bool
Verbose int
// contains filtered or unexported fields
}
Executor runs Ansible playbooks.
func NewExecutor ¶
NewExecutor creates a new playbook executor.
func (*Executor) SetInventory ¶
SetInventory loads inventory from a file.
func (*Executor) SetInventoryDirect ¶
SetInventoryDirect sets inventory directly.
type Facts ¶
type Facts struct {
Hostname string `json:"ansible_hostname"`
FQDN string `json:"ansible_fqdn"`
OS string `json:"ansible_os_family"`
Distribution string `json:"ansible_distribution"`
Version string `json:"ansible_distribution_version"`
Architecture string `json:"ansible_architecture"`
Kernel string `json:"ansible_kernel"`
Memory int64 `json:"ansible_memtotal_mb"`
CPUs int `json:"ansible_processor_vcpus"`
IPv4 string `json:"ansible_default_ipv4_address"`
}
Facts holds gathered facts about a host.
type Host ¶
type Host struct {
AnsibleHost string `yaml:"ansible_host,omitempty"`
AnsiblePort int `yaml:"ansible_port,omitempty"`
AnsibleUser string `yaml:"ansible_user,omitempty"`
AnsiblePassword string `yaml:"ansible_password,omitempty"`
AnsibleSSHPrivateKeyFile string `yaml:"ansible_ssh_private_key_file,omitempty"`
AnsibleConnection string `yaml:"ansible_connection,omitempty"`
AnsibleBecomePassword string `yaml:"ansible_become_password,omitempty"`
// Custom vars
Vars map[string]any `yaml:",inline"`
}
Host represents a host in inventory.
type Inventory ¶
type Inventory struct {
All *InventoryGroup `yaml:"all"`
}
Inventory represents Ansible inventory.
type InventoryGroup ¶
type InventoryGroup struct {
Hosts map[string]*Host `yaml:"hosts,omitempty"`
Children map[string]*InventoryGroup `yaml:"children,omitempty"`
Vars map[string]any `yaml:"vars,omitempty"`
}
InventoryGroup represents a group in inventory.
type LoopControl ¶
type LoopControl struct {
LoopVar string `yaml:"loop_var,omitempty"`
IndexVar string `yaml:"index_var,omitempty"`
Label string `yaml:"label,omitempty"`
Pause int `yaml:"pause,omitempty"`
Extended bool `yaml:"extended,omitempty"`
}
LoopControl controls loop behavior.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser handles Ansible YAML parsing.
func (*Parser) ParseInventory ¶
ParseInventory parses an Ansible inventory file.
func (*Parser) ParsePlaybook ¶
ParsePlaybook parses an Ansible playbook file.
type Play ¶
type Play struct {
Name string `yaml:"name"`
Hosts string `yaml:"hosts"`
Connection string `yaml:"connection,omitempty"`
Become bool `yaml:"become,omitempty"`
BecomeUser string `yaml:"become_user,omitempty"`
GatherFacts *bool `yaml:"gather_facts,omitempty"`
Vars map[string]any `yaml:"vars,omitempty"`
PreTasks []Task `yaml:"pre_tasks,omitempty"`
Tasks []Task `yaml:"tasks,omitempty"`
PostTasks []Task `yaml:"post_tasks,omitempty"`
Roles []RoleRef `yaml:"roles,omitempty"`
Handlers []Task `yaml:"handlers,omitempty"`
Tags []string `yaml:"tags,omitempty"`
Environment map[string]string `yaml:"environment,omitempty"`
Serial any `yaml:"serial,omitempty"` // int or string
MaxFailPercent int `yaml:"max_fail_percentage,omitempty"`
}
Play represents a single play in a playbook.
type Playbook ¶
type Playbook struct {
Plays []Play `yaml:",inline"`
}
Playbook represents an Ansible playbook.
type RoleRef ¶
type RoleRef struct {
Role string `yaml:"role,omitempty"`
Name string `yaml:"name,omitempty"` // Alternative to role
TasksFrom string `yaml:"tasks_from,omitempty"`
Vars map[string]any `yaml:"vars,omitempty"`
When any `yaml:"when,omitempty"`
Tags []string `yaml:"tags,omitempty"`
}
RoleRef represents a role reference in a play.
type SSHClient ¶
type SSHClient struct {
// contains filtered or unexported fields
}
SSHClient handles SSH connections to remote hosts.
func NewSSHClient ¶
NewSSHClient creates a new SSH client.
func (*SSHClient) FileExists ¶
FileExists checks if a file exists on the remote host.
func (*SSHClient) Run ¶
func (c *SSHClient) Run(ctx context.Context, cmd string) (stdout, stderr string, exitCode int, err error)
Run executes a command on the remote host.
func (*SSHClient) RunScript ¶
func (c *SSHClient) RunScript(ctx context.Context, script string) (stdout, stderr string, exitCode int, err error)
RunScript runs a script on the remote host.
type SSHConfig ¶
type SSHConfig struct {
Host string
Port int
User string
Password string
KeyFile string
Become bool
BecomeUser string
BecomePass string
Timeout time.Duration
Insecure bool
}
SSHConfig holds SSH connection configuration.
type Task ¶
type Task struct {
Name string `yaml:"name,omitempty"`
Module string `yaml:"-"` // Derived from the module key
Args map[string]any `yaml:"-"` // Module arguments
Register string `yaml:"register,omitempty"`
When any `yaml:"when,omitempty"` // string or []string
Loop any `yaml:"loop,omitempty"` // string or []any
LoopControl *LoopControl `yaml:"loop_control,omitempty"`
Vars map[string]any `yaml:"vars,omitempty"`
Environment map[string]string `yaml:"environment,omitempty"`
ChangedWhen any `yaml:"changed_when,omitempty"`
FailedWhen any `yaml:"failed_when,omitempty"`
IgnoreErrors bool `yaml:"ignore_errors,omitempty"`
NoLog bool `yaml:"no_log,omitempty"`
Become *bool `yaml:"become,omitempty"`
BecomeUser string `yaml:"become_user,omitempty"`
Delegate string `yaml:"delegate_to,omitempty"`
RunOnce bool `yaml:"run_once,omitempty"`
Tags []string `yaml:"tags,omitempty"`
Block []Task `yaml:"block,omitempty"`
Rescue []Task `yaml:"rescue,omitempty"`
Always []Task `yaml:"always,omitempty"`
Notify any `yaml:"notify,omitempty"` // string or []string
Retries int `yaml:"retries,omitempty"`
Delay int `yaml:"delay,omitempty"`
Until string `yaml:"until,omitempty"`
// Include/import directives
IncludeTasks string `yaml:"include_tasks,omitempty"`
ImportTasks string `yaml:"import_tasks,omitempty"`
IncludeRole *struct {
Name string `yaml:"name"`
TasksFrom string `yaml:"tasks_from,omitempty"`
Vars map[string]any `yaml:"vars,omitempty"`
} `yaml:"include_role,omitempty"`
ImportRole *struct {
Name string `yaml:"name"`
TasksFrom string `yaml:"tasks_from,omitempty"`
Vars map[string]any `yaml:"vars,omitempty"`
} `yaml:"import_role,omitempty"`
// contains filtered or unexported fields
}
Task represents an Ansible task.
type TaskResult ¶
type TaskResult struct {
Changed bool `json:"changed"`
Failed bool `json:"failed"`
Skipped bool `json:"skipped"`
Msg string `json:"msg,omitempty"`
Stdout string `json:"stdout,omitempty"`
Stderr string `json:"stderr,omitempty"`
RC int `json:"rc,omitempty"`
Results []TaskResult `json:"results,omitempty"` // For loops
Data map[string]any `json:"data,omitempty"` // Module-specific data
Duration time.Duration `json:"duration,omitempty"`
}
TaskResult holds the result of executing a task.