ansibleinv

package
v0.28.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package ansibleinv translates an Ansible inventory into the ZarfCluster document cargoship installs from. Ansible resolves the inventory -- group membership, group_vars, host_vars, dynamic inventory plugins, and everything else its own precedence rules cover -- and hands the result here already merged. Nothing in this package parses an inventory file, because reproducing those rules in Go would reproduce them wrongly.

Ansible supplies the inventory; it does not connect to the fleet. The translated document goes to cargoship's own phase pipeline, which opens every SSH connection itself from the management node.

Index

Constants

View Source
const (
	VarBastion          = Prefix + "bastion"
	VarEnvironment      = Prefix + "environment"
	VarFiles            = Prefix + "files"
	VarHost             = Prefix + "host"
	VarHostname         = Prefix + "hostname"
	VarNodeLabels       = Prefix + "node_labels"
	VarNodeTaints       = Prefix + "node_taints"
	VarPrivateAddress   = Prefix + "private_address"
	VarPrivateInterface = Prefix + "private_interface"
	VarProfile          = Prefix + "profile"
)

The variables cargoship reads out of the Ansible namespace.

View Source
const (
	VarAnsibleHost    = "ansible_host"
	VarAnsiblePort    = "ansible_port"
	VarAnsibleUser    = "ansible_user"
	VarAnsibleKeyFile = "ansible_ssh_private_key_file"
)

The Ansible connection variables cargoship reads. Everything else under ansible_ is ignored: there are hundreds of them, they belong to Ansible's own connection plugins, and cargoship does not connect the way Ansible does.

View Source
const Prefix = "cargoship_"

Prefix is the namespace for the host variables that configure cargoship. A variable under it that this package does not know is an error rather than a value ignored, because a misspelled variable is indistinguishable from an unset one at install time.

Variables

This section is empty.

Functions

func DefaultRoleGroups

func DefaultRoleGroups() map[string][]string

DefaultRoleGroups maps each cargoship role onto an Ansible group of the same name. It names cargoship's own roles rather than guessing at an Ansible convention, because there is no one convention to guess at: an inventory may call its control plane `control_plane`, `masters`, `etcd`, or anything else. An operator whose groups are named otherwise says so.

func Translate

func Translate(in Input, meta ClusterMeta) (*cluster.ZarfCluster, error)

Translate builds a ZarfCluster from a resolved Ansible inventory.

Host order in the result is load-bearing: ConfigureEngine makes the first controller the leader, so the leader is the first host of the first group listed under RoleGroups ["controller"]. Controllers come before workers, and within a role the groups are walked in the order RoleGroups lists them, each group's hosts in Ansible's inventory order.

The result is checked against the embedded inventory schema before it is returned, so a translation mistake is reported as the field it landed in rather than as a phase failing against a live host some minutes into an apply.

Types

type ClusterMeta

type ClusterMeta struct {
	// Name sets metadata.name, which cargoship uses as the kubeconfig context name.
	Name string `json:"name"`
	// LoadBalancer is the hostname clients use to reach the control plane.
	LoadBalancer string `json:"loadbalancer"`
	// Profiles maps a profile name to the host and engine overrides a host can select.
	Profiles map[string]cluster.ZarfClusterProfiles `json:"profiles,omitempty"`
	// Registries lists the container registries the cluster uses.
	Registries []cluster.ZarfClusterRegistries `json:"registries,omitempty"`
	// Values overrides the values the distro package was built with.
	Values map[string]any `json:"values,omitempty"`
}

ClusterMeta is everything the generated document needs that no host carries: the parts of a ZarfCluster that describe the cluster rather than a node.

type Input

type Input struct {
	// Groups maps an Ansible group name to the hosts in it, in inventory order.
	Groups map[string][]string `json:"groups"`
	// HostVars maps an inventory hostname to the variables Ansible resolved for it.
	HostVars map[string]map[string]any `json:"hostvars"`
	// RoleGroups maps a cargoship role to the Ansible groups whose hosts take that role.
	RoleGroups map[string][]string `json:"roleGroups"`
}

Input is the inventory as Ansible resolved it. Groups and HostVars are Ansible's own `groups` and `hostvars`, projected by the action plugin; RoleGroups is the operator's mapping from a cargoship role onto the Ansible groups that carry it.

type Request

type Request struct {
	Input
	// Cluster holds the settings that belong to the cluster rather than to any host.
	Cluster ClusterMeta `json:"cluster"`
}

Request is one complete translation: the inventory Ansible resolved, plus the cluster-wide settings an inventory has no way to carry. It is what the action plugin sends and what `cargoship inventory from-ansible` reads, so the same document that reproduces a translation by hand is the one a playbook produced.

func Decode

func Decode(b []byte) (*Request, error)

Decode reads a Request, refusing a key it does not know. A misspelled key here is a setting silently unset, and the two cases this decodes -- a playbook's projection and an operator's hand-written file -- both fail quietly without the check.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL