feat(ansible): refine AX docs and naming
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
c276c343bc
commit
56457c6f42
2 changed files with 19 additions and 11 deletions
22
modules.go
22
modules.go
|
|
@ -1543,41 +1543,41 @@ func (e *Executor) moduleDnf(ctx context.Context, client sshExecutorClient, args
|
|||
return e.moduleRPM(ctx, client, args, "dnf")
|
||||
}
|
||||
|
||||
func (e *Executor) moduleRPM(ctx context.Context, client sshExecutorClient, args map[string]any, manager string) (*TaskResult, error) {
|
||||
func (e *Executor) moduleRPM(ctx context.Context, client sshExecutorClient, args map[string]any, packageManager string) (*TaskResult, error) {
|
||||
names := normalizeStringArgs(args["name"])
|
||||
state := getStringArg(args, "state", "present")
|
||||
updateCache := getBoolArg(args, "update_cache", false)
|
||||
|
||||
if updateCache && manager != "rpm" {
|
||||
_, _, _, _ = client.Run(ctx, sprintf("%s makecache -y", manager))
|
||||
if updateCache && packageManager != "rpm" {
|
||||
_, _, _, _ = client.Run(ctx, sprintf("%s makecache -y", packageManager))
|
||||
}
|
||||
|
||||
var cmd string
|
||||
switch state {
|
||||
case "present", "installed":
|
||||
if len(names) > 0 {
|
||||
if manager == "rpm" {
|
||||
if packageManager == "rpm" {
|
||||
cmd = sprintf("rpm -ivh %s", join(" ", names))
|
||||
} else {
|
||||
cmd = sprintf("%s install -y -q %s", manager, join(" ", names))
|
||||
cmd = sprintf("%s install -y -q %s", packageManager, join(" ", names))
|
||||
}
|
||||
}
|
||||
case "absent", "removed":
|
||||
if len(names) > 0 {
|
||||
if manager == "rpm" {
|
||||
if packageManager == "rpm" {
|
||||
cmd = sprintf("rpm -e %s", join(" ", names))
|
||||
} else {
|
||||
cmd = sprintf("%s remove -y -q %s", manager, join(" ", names))
|
||||
cmd = sprintf("%s remove -y -q %s", packageManager, join(" ", names))
|
||||
}
|
||||
}
|
||||
case "latest":
|
||||
if len(names) > 0 {
|
||||
if manager == "rpm" {
|
||||
if packageManager == "rpm" {
|
||||
cmd = sprintf("rpm -Uvh %s", join(" ", names))
|
||||
} else if manager == "dnf" {
|
||||
cmd = sprintf("%s upgrade -y -q %s", manager, join(" ", names))
|
||||
} else if packageManager == "dnf" {
|
||||
cmd = sprintf("%s upgrade -y -q %s", packageManager, join(" ", names))
|
||||
} else {
|
||||
cmd = sprintf("%s update -y -q %s", manager, join(" ", names))
|
||||
cmd = sprintf("%s update -y -q %s", packageManager, join(" ", names))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -929,6 +929,8 @@ func NormalizeModule(name string) string {
|
|||
//
|
||||
// Example:
|
||||
//
|
||||
// parser := NewParser("/workspace/inventory")
|
||||
// inventory, _ := parser.ParseInventory("/workspace/inventory/hosts.yml")
|
||||
// hosts := GetHosts(inventory, "webservers")
|
||||
func GetHosts(inventory *Inventory, pattern string) []string {
|
||||
if pattern == "all" {
|
||||
|
|
@ -1099,6 +1101,8 @@ func subtractHosts(base, extra []string) []string {
|
|||
//
|
||||
// Example:
|
||||
//
|
||||
// parser := NewParser("/workspace/inventory")
|
||||
// inventory, _ := parser.ParseInventory("/workspace/inventory/hosts.yml")
|
||||
// hostsSeq := GetHostsIter(inventory, "all")
|
||||
func GetHostsIter(inventory *Inventory, pattern string) iter.Seq[string] {
|
||||
hosts := GetHosts(inventory, pattern)
|
||||
|
|
@ -1147,6 +1151,8 @@ func collectAllHosts(group *InventoryGroup, seen map[string]bool, hosts *[]strin
|
|||
//
|
||||
// Example:
|
||||
//
|
||||
// parser := NewParser("/workspace/inventory")
|
||||
// inventory, _ := parser.ParseInventory("/workspace/inventory/hosts.yml")
|
||||
// hostsSeq := AllHostsIter(inventory.All)
|
||||
func AllHostsIter(group *InventoryGroup) iter.Seq[string] {
|
||||
return func(yield func(string) bool) {
|
||||
|
|
@ -1200,6 +1206,8 @@ func hasHost(group *InventoryGroup, name string) bool {
|
|||
//
|
||||
// Example:
|
||||
//
|
||||
// parser := NewParser("/workspace/inventory")
|
||||
// inventory, _ := parser.ParseInventory("/workspace/inventory/hosts.yml")
|
||||
// hostVars := GetHostVars(inventory, "web1")
|
||||
func GetHostVars(inventory *Inventory, hostname string) map[string]any {
|
||||
vars := make(map[string]any)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue