Set up multi-environment configurations
✓Works with OpenClaudeYou are a DevOps engineer setting up multi-environment configurations. The user wants to manage separate configs for dev, staging, and production environments with proper isolation and override mechanisms.
What to check first
- Whether you're using
.envfiles, YAML configs, or a dedicated config management tool (dotenv, Viper, Consul, etc.) - If your application framework has built-in environment support (Django
settings/, Spring profiles, etc.) - Whether secrets are already stored separately from config files
- Current directory structure and how environments are being identified
Steps
- Create base environment directory structure with
mkdir -p config/{dev,staging,production}to isolate each environment's configuration files - Define a
.env.examplefile in the root with all required keys but no values, then rungit add .env.exampleand add.envto.gitignoreto ensure secrets aren't committed - Create environment-specific files like
config/dev/app.yml,config/staging/app.yml,config/production/app.ymlwith environment-specific values (database URLs, API endpoints, log levels, etc.) - Set the active environment using an
ENVorENVIRONMENTvariable: exportENVIRONMENT=developmentin shell, or add it to systemd unit files withEnvironment=ENVIRONMENT=production - Implement a config loader in your application code that reads from the correct directory based on the
ENVIRONMENTvariable and merges base config with environment-specific overrides - Use
python-dotenv(Python),dotenvnpm package (Node), or similar to load.env.development,.env.staging,.env.productionfiles withload_dotenv()or equivalent - Validate config on startup by checking required keys exist and have correct types—fail fast if critical config is missing
- Document the environment variables and their purposes in a
CONFIG.mdfile with examples for each environment
Code
import os
from pathlib import Path
from dotenv import load_dotenv
import yaml
import logging
class ConfigManager:
def __init__(self, env: str = None):
self.env = env or os.getenv('ENVIRONMENT', 'development')
self.base_path = Path(__file__).parent / 'config'
self.config = {}
self._load_config()
def _load_config(self):
"""Load base config, then environment-specific overrides"""
# Load base config
base_file = self.base_path / 'base.yml'
if base_file.exists():
with open(base_file) as f:
self.config = yaml.safe_load(f) or {}
# Load environment-specific config
env_file = self.base_path / self.env / 'app.yml'
if env_file.exists():
with open(env_file) as f:
env_config = yaml.safe_load(f) or {}
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related DevOps & CI/CD Skills
Other Claude Code skills in the same category — free to download.
GitHub Actions Setup
Create GitHub Actions workflow files
GitLab CI Setup
Create .gitlab-ci.yml pipeline configuration
Jenkins Pipeline
Generate Jenkinsfile for CI/CD
Deploy Script
Create deployment scripts for various platforms
Env Manager
Manage environment variables across environments
Infrastructure as Code
Generate Terraform/Pulumi configurations
Auto Release
Set up automated releases with semantic versioning
Rollback Script
Create rollback procedures and scripts
Want a DevOps & CI/CD skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.