https://github.com/arillso/go.ansible
Go module for running Ansible Commandors on a Linux system.
https://github.com/arillso/go.ansible
go golang library module
Last synced: 12 months ago
JSON representation
Go module for running Ansible Commandors on a Linux system.
- Host: GitHub
- URL: https://github.com/arillso/go.ansible
- Owner: arillso
- License: mit
- Created: 2020-03-30T17:04:28.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-06-22T00:07:26.000Z (about 1 year ago)
- Last Synced: 2025-06-22T01:20:05.698Z (about 1 year ago)
- Topics: go, golang, library, module
- Language: Go
- Size: 60.5 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: LICENSE
Awesome Lists containing this project
README
# GO Ansible
[](LICENSE)
[](https://pkg.go.dev/github.com/arillso/go.ansible?tab=doc)
[](https://github.com/arillso/go.ansible/releases)
[](https://goreportcard.com/report/github.com/arillso/go.ansible)
## Overview
**GO Ansible** is a Go module designed to programmatically run Ansible playbooks on Linux systems. It supports:
- **Automated Playbook Resolution:** Resolves file patterns (glob) and validates playbook existence.
- **Temporary File Management:** Manages temporary files (SSH private keys and Vault passwords) securely.
- **Galaxy Integration:** Installs roles and collections from Ansible Galaxy with extensive configuration.
- **Flexible Configuration:** Customizes Ansible commands (inventories, extra vars, SSH/user options, verbosity).
- **Enhanced Environment Variables:** Sets variables like `ANSIBLE_CONFIG` based on provided configurations.
- **Debug and Traceability:** Provides detailed command tracing in debug mode for easier troubleshooting.
## Features
### Playbook Execution and Management
- **Playbook Resolution:** Supports file names and glob patterns for playbook identification.
- **Temporary Files:** Manages SSH keys and Vault passwords, cleaning them up automatically.
- **Inventory Management:** Supports inline (`localhost,`) and file-based inventories.
### Advanced Options
- **Command Building:** Constructs commands with options (check/diff modes, user settings, forks).
- **Extra Vars Management:** Passes multiple variables to playbooks with `--extra-vars`.
- **Verbose Logging:** Offers configurable verbosity (up to `-vvvv`) for detailed logs.
### Galaxy Integration
- **Roles and Collections:** Installs Galaxy roles and collections using a configuration file.
- **Customization:** API keys, server URLs, certificate ignoring, timeouts, dependencies handling.
- **Upgrades:** Provides options to upgrade existing Galaxy collections.
### Debugging and Error Handling
- **Command Tracing:** Debug mode prints every executed command for tracing.
- **Context-Based Execution:** Uses Go’s `context.Context` for command management and cancellation.
- **Error Reporting:** Wraps errors with contextual information using `github.com/pkg/errors`.
## Installation
Ensure you have [Go (version 1.23 or higher)](https://golang.org/dl/) installed, then run:
```bash
go mod download
```
## Usage
The module serves as a foundation for executing Ansible playbooks in applications. Example:
1. **Create and Configure a Playbook Instance:**
```go
package main
import (
"context"
"log"
"github.com/arillso/go.ansible/ansible"
)
func main() {
pb := ansible.NewPlaybook()
pb.Config.Playbooks = []string{"site.yml"}
pb.Config.Inventories = []string{"localhost,"}
pb.Config.PrivateKey = "your ssh private key..."
pb.Config.VaultPassword = "your vault password..."
if err := pb.Exec(context.Background()); err != nil {
log.Fatalf("Execution failed: %v", err)
}
}
```
2. **Command Construction and Execution:**
The module automatically constructs commands and manages dependencies (like Galaxy installations).
## Testing
The repository includes tests covering functionalities such as playbook resolution, temporary files, and extra vars:
```bash
go test -v ./...
```
## CI/CD and Linters
- **Continuous Integration:** GitHub Actions automatically run tests on push and pull requests.
- **Code Quality:** Makefile targets for formatting and linting ensure best practices.
- **Pre-commit Hooks:** Automatically fix issues like trailing whitespace and line endings.
## License
Licensed under the [MIT License](LICENSE).
## Copyright
(c) 2022, Arillso