python-devops-automation
Skill2 starsChanged 10 months agoMITView on GitHub
DevOps automation with Python. Use this skill when automating infrastructure, working with AWS (boto3), building CLIs (click/typer), managing subprocesses, or working with Docker/Kubernetes from Python. Covers boto3 patterns, CLI design, subprocess management, and infrastructure automation.
- Reads credentials
In this repository38 other files it gives its agents.
- Data Engineering Cloud InfrastructureSkill
- data-eng-data-qualitySkill
- data-eng-streaming-patternsSkill
- data-eng-testing-patternsSkill
- data-eng-warehouse-patternsSkill
- DevOps CI/CD PatternsSkill
- devops-docker-patternsSkill
- devops-monitoring-observabilitySkill
- devops-terraform-patternsSkill
- git-advanced-operationsSkill
- git-workflow-patternsSkill
- modern-python-patternsSkill
- python-api-developmentSkill
- python-async-patternsSkill
- python-data-pipelinesSkill
- python-data-wranglingSkill
- python-error-handlingSkill
- python-package-developmentSkill
- python-performanceSkill
- python-testingSkill
- customizing-vectors-rSkill
- designing-oop-rSkill
- developing-packages-rSkill
- metaprogramming-rlangSkill
- optimizing-rSkill
- writing-tidyverse-rSkill
- sql-advanced-featuresSkill
- sql-analytics-patternsSkill
- sql-data-modelingSkill
- SQL Integration PatternsSkill
- sql-query-fundamentalsSkill
- sql-query-optimizationSkill
- sql-transformationsSkill
- API DesignSkill
- webdev-html-css-patternsSkill
- webdev-javascript-fundamentalsSkill
- webdev-react-patternsSkill
- webdev-typescript-patternsSkill
The file
Files
Python DevOps Automation
Automation patterns for infrastructure, cloud, and operational tasks.
Core Principles
- Idempotent operations - Safe to run multiple times
- Error handling first - Anticipate failures
- Logging over print - Structured, searchable logs
- Configuration external - Environment variables, config files
CLI Development with Click
Use click for command-line tools
import click
@click.command()
@click.option('--count', default=1, help='Number of times to run')
@click.option('--verbose', is_flag=True, help='Verbose output')
@click.argument('name')
def greet(count, verbose, name):
"""Simple CLI tool."""
for _ in range(count):
if verbose:
click.echo(f'Greeting: Hello {name}!')
else:
click.echo(f'Hello {name}!')
if __name__ == '__main__':
greet()See cli-patterns.md for:
- Command groups
- Progress bars
- File handling
- Click vs Typer
AWS Automation with Boto3
Use boto3 for AWS operations
import boto3
# S3 operations
s3 = boto3.client('s3')
s3.upload_file('local.txt', 'bucket-name', 'remote.txt')
# EC2 operations
ec2 = boto3.resource('ec2')
instances = ec2.instances.filter(
Filters=[{'Name': 'tag:Environment', 'Values': ['production']}]
)See boto3-patterns.md for:
- Resource vs client
- Pagination
- Error handling
- Credential management
Subprocess Management
Use subprocess for external commands
import subprocess
# Run command, capture output
result = subprocess.run(
['ls', '-la'],
capture_output=True,
text=True,
check=True
)
print(result.stdout)
# Stream output in real-time
process = subprocess.Popen(
['long-running-command'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
for line in process.stdout:
print(line, end='')
returncode = process.wait()See subprocess-patterns.md for:
- Error handling
- Timeouts
- Shell=True dangers
- Environment variables
Docker Automation
Use docker-py for container management
import docker
client = docker.from_env()
# Run container
container = client.containers.run(
"ubuntu:latest",
"echo hello world",
detach=True
)
# Wait for completion
container.wait()
print(container.logs().decode())See docker-patterns.md.
Configuration Management
import os
from pathlib import Path
from dataclasses import dataclass
import tomli
@dataclass
class Config:
api_key: str
region: str
debug: bool = False
@classmethod
def from_env(cls):
"""Load from environment variables."""
return cls(
api_key=os.environ['API_KEY'],
region=os.getenv('AWS_REGION', 'us-east-1'),
debug=os.getenv('DEBUG', 'false').lower() == 'true'
)
@classmethod
def from_file(cls, path: Path):
"""Load from TOML config file."""
with open(path, 'rb') as f:
data = tomli.load(f)
return cls(**data)See config-patterns.md.
Logging Best Practices
import logging
from pathlib import Path
# Setup logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('app.log'),
logging.StreamHandler()
]
)
logger = logging.getLogger(__name__)
def deploy_app():
logger.info("Starting deployment")
try:
# Deployment logic
logger.debug("Uploading files...")
logger.info("Deployment successful")
except Exception as e:
logger.error(f"Deployment failed: {e}", exc_info=True)
raiseSee logging-patterns.md.
source: DevOps with Python
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

