Configuration Troubleshooting
This guide helps you diagnose and resolve common configuration issues in Xec. Each section covers specific problems, their causes, and solutions.
Diagnostic Toolsβ
Configuration Debuggingβ
# Enable debug output
xec --debug config show
# Trace configuration loading
xec --trace config validate
# Show configuration sources
xec config sources
# Test configuration resolution
xec config resolve --var database.host
Built-in Diagnosticsβ
# Run full diagnostics
xec doctor
# Check specific component
xec doctor --check configuration
xec doctor --check targets
xec doctor --check connectivity
Common Issuesβ
YAML Syntax Errorsβ
Problem: Invalid YAMLβ
# Error: Mapping values are not allowed here
tasks:
deploy: echo "test"
target: production # Wrong indentation
Solutionβ
# Correct indentation
tasks:
deploy:
command: echo "test"
target: production
Debugging Tipsβ
# Validate YAML syntax
yamllint .xec/config.yaml
# Use YAML validator
python -c "import yaml; yaml.safe_load(open('.xec/config.yaml'))"
# Common YAML issues:
# - Tabs instead of spaces
# - Inconsistent indentation
# - Missing colons
# - Unclosed quotes
Variable Resolution Issuesβ
Problem: Undefined Variableβ
Error: Variable 'database.password' is not defined
tasks:
connect:
command: psql -p ${database.password}
Solutionsβ
1. Define the Variableβ
vars:
database:
password: ${secrets.db_password}
2. Provide Default Valueβ
tasks:
connect:
command: psql -p ${database.password:-default_password}
3. Check Variable Pathβ
# List all variables
xec config show --vars
# Check specific variable
xec config get vars.database
Problem: Circular Variable Referenceβ
Error: Circular variable reference detected: a -> b -> c -> a
vars:
a: ${b}
b: ${c}
c: ${a}
Solutionβ
# Break the circular dependency
vars:
a: "initial_value"
b: ${a}
c: ${b}
Target Connection Issuesβ
Problem: SSH Connection Failedβ
Error: Failed to connect to hosts.production: Connection refused
Diagnostic Stepsβ
# Test SSH connectivity
xec test hosts.production --verbose
# Check SSH configuration
xec config show --target hosts.production
# Manual SSH test
ssh -v user@host -p 22
Common Solutionsβ
1. Check SSH Configurationβ
targets:
hosts:
production:
host: prod.example.com
port: 22 # Ensure correct port
username: deploy # Verify username
privateKey: ~/.ssh/id_rsa # Check key path
2. Fix Key Permissionsβ
# SSH keys must have correct permissions
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
chmod 700 ~/.ssh
3. Add Host to Known Hostsβ
# Add host key
ssh-keyscan -H prod.example.com >> ~/.ssh/known_hosts
Problem: Docker Connection Failedβ
Error: Cannot connect to Docker daemon
Solutionsβ
1. Check Docker Serviceβ
# Ensure Docker is running
docker info
# Start Docker if needed
sudo systemctl start docker # Linux
open -a Docker # macOS
2. Configure Docker Socketβ
targets:
containers:
app:
socketPath: /var/run/docker.sock # Default
# Or for remote Docker
dockerHost: tcp://docker-host:2376
Problem: Kubernetes Connection Failedβ
Error: Unable to connect to kubernetes cluster
Solutionsβ
1. Check Kubeconfigβ
# Verify kubeconfig
kubectl config view
kubectl cluster-info
2. Configure Contextβ
targets:
pods:
app:
kubeconfig: ~/.kube/config
context: production-cluster
namespace: default
Task Execution Issuesβ
Problem: Task Not Foundβ
Error: Task 'deploy' not found
Solutionsβ
# List available tasks
xec task list
# Search for tasks
xec task search deploy
# Check task definition
xec config show --tasks
Problem: Task Parameters Missingβ
Error: Required parameter 'version' not provided
Solutionβ
# Provide parameter
xec run deploy --version 1.2.3
# Or set default
tasks:
deploy:
params:
- name: version
default: "latest"
Problem: Task Step Failedβ
Error: Step 'build' failed with exit code 1
Debugging Stepsβ
# Run task with debug output
xec run deploy --debug
# Run specific step
xec run deploy --only-step build
# Dry run
xec run deploy --dry-run
Profile Issuesβ
Problem: Profile Not Foundβ
Error: Profile 'production' not found
Solutionsβ
# List available profiles
xec config profiles
# Check profile definition
xec config show --profiles
Problem: Profile Inheritance Errorβ
Error: Cannot extend profile 'base': not found
Solutionβ
# Ensure base profile exists
profiles:
base:
vars:
environment: base
production:
extends: base # Now valid
vars:
environment: production
Environment Variable Issuesβ
Problem: Environment Variable Not Setβ
Error: Environment variable 'API_KEY' is required but not set
Solutionsβ
1. Set Environment Variableβ
export API_KEY="your-api-key"
xec run deploy
2. Use .env Fileβ
# .env
API_KEY=your-api-key
# Load environment
source .env && xec run deploy
3. Provide Defaultβ
vars:
apiKey: ${env.API_KEY:-development-key}
Permission Issuesβ
Problem: Permission Deniedβ
Error: Permission denied: /var/log/app.log
Solutionsβ
1. Use Sudoβ
targets:
hosts:
server:
sudo:
enabled: true
password: ${secrets.sudo_password}
2. Fix File Permissionsβ
# Change ownership
sudo chown $(whoami) /var/log/app.log
# Change permissions
chmod 644 /var/log/app.log
3. Run as Different Userβ
targets:
containers:
app:
user: root # Or appropriate user
Secret Management Issuesβ
Problem: Secret Not Foundβ
Error: Secret 'database_password' not found
Solutionsβ
1. Add Secretβ
# Add secret to local store
xec secret set database_password
# Or use environment
export XEC_SECRET_DATABASE_PASSWORD="password"
2. Configure Secret Providerβ
secrets:
provider: vault
config:
address: https://vault.example.com
token: ${env.VAULT_TOKEN}
Performance Issuesβ
Problem: Slow Configuration Loadingβ
Solutionsβ
1. Optimize Importsβ
# Instead of multiple imports
$import:
- tasks/*.yaml # Glob pattern is faster
# Than individual files
$import:
- tasks/deploy.yaml
- tasks/backup.yaml
- tasks/monitoring.yaml
2. Cache Configurationβ
# Enable configuration cache
xec config cache enable
# Clear cache if needed
xec config cache clear
Problem: Connection Pool Exhaustedβ
Error: Connection pool exhausted for hosts.production
Solutionβ
targets:
hosts:
production:
connectionPool:
min: 2
max: 20 # Increase max connections
idleTimeout: 300000
Validation Errorsβ
Problem: Schema Validation Failedβ
Error: Configuration does not match schema: version is required
Solutionβ
# Add required fields
version: "1.0" # Required
name: myapp # Optional but recommended
Problem: Type Mismatchβ
Error: Expected number for 'timeout', got string
Solutionβ
# Use correct types
timeout: 30000 # Number (milliseconds)
# Not: timeout: "30000" # String
Import and Module Issuesβ
Problem: Import File Not Foundβ
Error: Cannot import 'profiles/production.yaml': File not found
Solutionsβ
# Check file exists
ls -la .xec/profiles/
# Create missing file
touch .xec/profiles/production.yaml
# Use correct path
$import:
- ./profiles/production.yaml # Relative to config file
Debugging Strategiesβ
1. Incremental Testingβ
# Test configuration step by step
xec config validate # Basic validation
xec test --all-targets # Test connectivity
xec run simple-task # Test simple task
xec run complex-task --dry-run # Test without execution
2. Isolation Testingβ
# Create minimal test configuration
# test-config.yaml
version: "1.0"
tasks:
test:
command: echo "test"
# Test isolated configuration
xec --config test-config.yaml run test
3. Verbose Outputβ
# Maximum verbosity
xec --debug --trace --verbose run deploy
# Log to file
xec --debug run deploy 2>&1 | tee debug.log
4. Configuration Inspectionβ
# Show resolved configuration
xec config show --resolved
# Show specific section
xec config show --targets
xec config show --tasks
xec config show --vars
# Export configuration
xec config export > config-snapshot.yaml
Recovery Proceduresβ
Configuration Backupβ
# Backup configuration
cp -r .xec .xec.backup
# Version control
git add .xec/
git commit -m "Configuration backup"
Safe Modeβ
# Run with minimal configuration
xec --safe-mode run task
# Skip validation
xec --skip-validation run task
Reset Configurationβ
# Reset to defaults
xec config reset
# Regenerate configuration
xec init --force
Getting Helpβ
Built-in Helpβ
# General help
xec help
# Command-specific help
xec help config
xec help run
# Show examples
xec examples
Support Resourcesβ
- Documentation: https://xec.sh/docs
- GitHub Issues: https://github.com/xec-sh/xec/issues
- Discord Community: https://discord.gg/xec
- Stack Overflow: Tag
xec-cli
Reporting Issuesβ
When reporting issues, include:
# System information
xec doctor --system-info > system-info.txt
# Configuration (sanitized)
xec config export --sanitize > config.yaml
# Debug log
xec --debug --trace [command] 2>&1 > debug.log
# Error message
# Include full error message and stack trace
Prevention Tipsβ
1. Use Version Controlβ
git add .xec/
git commit -m "Working configuration"
2. Test Changesβ
# Test before applying
xec config validate
xec run task --dry-run
3. Document Changesβ
# Add comments explaining configuration
vars:
# Production API endpoint (updated 2024-01-15)
apiUrl: https://api.example.com
4. Use Profilesβ
# Separate environments
profiles:
development: # Safe testing
production: # Stable configuration
5. Monitor Configurationβ
# Regular validation
xec config validate --schedule daily
# Configuration drift detection
xec config diff
Next Stepsβ
- Validation - Configuration validation
- Best Practices - Avoid common issues
See Alsoβ
- Configuration Overview - Configuration basics
- Known Issues - GitHub issues
- Community Forum - Community support