Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
DevOps & CI/CDintermediate

Multi-Env Config

Share

Set up multi-environment configurations

Works with OpenClaude

You 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 .env files, 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

  1. Create base environment directory structure with mkdir -p config/{dev,staging,production} to isolate each environment's configuration files
  2. Define a .env.example file in the root with all required keys but no values, then run git add .env.example and add .env to .gitignore to ensure secrets aren't committed
  3. Create environment-specific files like config/dev/app.yml, config/staging/app.yml, config/production/app.yml with environment-specific values (database URLs, API endpoints, log levels, etc.)
  4. Set the active environment using an ENV or ENVIRONMENT variable: export ENVIRONMENT=development in shell, or add it to systemd unit files with Environment=ENVIRONMENT=production
  5. Implement a config loader in your application code that reads from the correct directory based on the ENVIRONMENT variable and merges base config with environment-specific overrides
  6. Use python-dotenv (Python), dotenv npm package (Node), or similar to load .env.development, .env.staging, .env.production files with load_dotenv() or equivalent
  7. Validate config on startup by checking required keys exist and have correct types—fail fast if critical config is missing
  8. Document the environment variables and their purposes in a CONFIG.md file 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

Quick Info

Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
devopsenvironmentsconfig

Install command:

curl -o ~/.claude/skills/multi-env-config.md https://claude-skills-hub.vercel.app/skills/devops/multi-env-config.md

Related DevOps & CI/CD Skills

Other Claude Code skills in the same category — free to download.

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.