/devops-ai-cli

DevOps CLI using Go, Viper and Cobra

Primary LanguageGo

devops-ai-cli

devops-ai-cli is a personal CLI tool written in Go, powered by Cobra and Viper.

About

It's a cli tool that includes some of the following:

🚀 Installation

Prerequisites

You need Go installed. Check with:

go version

If Go is not installed, you can install version 1.24.0 on Linux

Read more
curl -fsSL https://golang.org/dl/go1.24.0.linux-amd64.tar.gz | sudo tar -C /usr/local -xzf -
export PATH=$PATH:/usr/local/go/bin
echo "export PATH=\$PATH:/usr/local/go/bin" >> ~/.bashrc
echo "export GOPATH=\$HOME/go" >> ~/.bashrc
echo "export GOROOT=/usr/local/go" >> ~/.bashrc

Now, verify installation:

go version

🛠️ Setup & Usage

1️⃣ Install Dependencies

go mod tidy

2️⃣ Build the CLI

go build -o devopscli main.go

✨ Features

🛠️ Initialize Configuration

The init command creates a default configuration file.

📌 Usage

./devopscli init

This will create a configuration file at ~/.config/devopscli/config.yaml

📌 Example Config (config.yaml)

openwebui:
  host: "http://localhost:3000"
  api_key: "your-api-key-here"
  model: "gpt-4-turbo"

debug: false

📌 Overriding the Config Location

By default, devopscli uses ~/.config/devopscli/config.yaml for its configuration and to use a custom location you can set DEVOPSCLI_CONFIG_LOCATION environment variable:

export DEVOPSCLI_CONFIG_LOCATION="$HOME/.devopscli/config.yaml"

📜 Render a Markdown File

The render command allows you to display Markdown files beautifully in the terminal.

Usage

./devopscli render -f example.md

Example

echo "# Hello, World!" > example.md
./devopscli render -f example.md

🤖 Explain Command

The explain command allows you to ask OpenWebUI AI for explanations on various topics,
and it returns a response formatted in Markdown.

Usage

./devopscli explain "what does the Kubernetes CrashLoopBackOff mean?"

Configuration

To use this command, configure OpenWebUI API details in one of two ways:

📌 Option 1: Using config.yaml

openwebui:
  host: "http://localhost:3000"
  api_key: "your-api-key-here"

📌 Option 2: Using Environment Variables

export OPENWEB_API_KEY="your-secret-api-key"
export OPENWEB_API_HOST="http://localhost:3000"

How It Works

✅ The CLI sends a request to OpenWebUI with your query.
✅ OpenWebUI processes the request and returns a response.
✅ The response is rendered as Markdown using glamour.

🤖 Query Command (Maintain Conversations)

The query command allows you to ask OpenWebUI AI questions while maintaining context across multiple queries.

📝 Basic Usage

./devopscli query "What is Kubernetes?"

Example Response

  # Kubernetes Explained
  Kubernetes is an open-source container orchestration system...
🆔 **Conversation ID**: 1

This assigns the question a Conversation ID (1), allowing follow-ups.

🔄 Continue a Conversation

To ask follow-up questions, use the --cid flag with the conversation ID:

./devopscli query "How does Kubernetes handle scaling?" --cid "1"

Example Response

  # Kubernetes Scaling
  - Uses Horizontal Pod Autoscaler (HPA)
  - Uses Cluster Autoscaler
  - Supports Vertical Pod Autoscaling

This maintains context and follows up on the previous question.

📋 List Saved Conversations

./devopscli query --list

Example Output

📝 **Previous Conversations:**
🆔 1: What is Kubernetes?
🆔 2: How does Kubernetes handle deployments?

This lets you see which past questions you can continue.

🗑️ Delete a Specific Conversation

./devopscli query --delete 1

✅ Removes conversation ID 1 from storage.

🚨 Clear All Conversations

./devopscli query --clear

🗑️ Deletes all stored conversations.

✨ Features

Maintains conversation history
Allows follow-up questions (--cid)
Lists previous queries (--list)
Deletes single (--delete) or all (--clear) conversations
Uses OpenWebUI API for intelligent responses
Outputs beautifully formatted Markdown responses

🚀 Optimize Command

The optimize command allows you to send a code or configuration file (e.g., YAML, JSON, Python, Terraform, Shell scripts) to OpenWebUI AI, which will analyze and provide optimization suggestions in Markdown format.

🔹 Usage

./devopscli optimize -f _extras/manifests/example-deployment.yaml 

Example for a Terraform file:

./devopscli optimize -f infra.tf

Example for a Python script:

./devopscli optimize -f script.py

⚙️ Configuration

To use this command, configure OpenWebUI API details via a config file or environment variables.

📌 Option 1: Using config.yaml

openwebui:
  host: "http://localhost:3000"
  api_key: "your-api-key-here"
  model: "gemma:2b"

📌 Option 2: Using Environment Variables

export OPENWEB_API_KEY="your-secret-api-key"
export OPENWEB_API_HOST="http://localhost:3000"

📝 Example Output

If you run:

./devopscli optimize -f _extras/manifests/example-deployment.yaml

The response from AI will be returned in markdown format.

✨ Summary

Supports multiple file types (YAML, JSON, .py, .tf, .sh, etc.)
Sends the file content to OpenWebUI for AI-based optimization
Receives Markdown suggestions and beautifully renders them in the terminal

🔍 Verify Installed Tools

The verify command checks whether required DevOps tools are installed on your system. It reads the list of tools from config.yaml and reports their availability.

📝 Usage

./devopscli verify

📌 Example Configuration

Define required tools in config.yaml:

tools:
  required:
    - kubectl
    - terraform
    - docker
    - helm
    - git
    - jq
    - curl

📌 Example Output

🔍 **Verifying Required Tools:**

✅ kubectl
❌ terraform (Not Installed)
✅ docker
✅ helm
✅ git
❌ jq (Not Installed)
✅ curl

💡 Features

Reads required tools from config.yaml
Checks if each tool is installed
Displays ✅ (installed) and ❌ (missing)
Fast and lightweight!

📚 Resources