Semaphore nutzt Git-Repositories als primäre Quelle für Ansible-Playbooks und ermöglicht dadurch professionelle Versionskontrolle und Kollaboration. Die Integration erfolgt über Repository-Definitionen innerhalb von Projekten.
Unterstützte Git-Provider:
Authentifizierungsmethoden:
SSH-basiert:
├── Deploy-Keys (Repository-spezifisch)
├── SSH-Agent-Forwarding
└── Private-Key-Authentifizierung
HTTPS-basiert:
├── Personal Access Tokens
├── OAuth-Token
└── Username/Password (nicht empfohlen)
Grundkonfiguration:
Repository Name: ansible-infrastructure
Git URL: git@github.com:company/ansible-infrastructure.git
Branch: main
SSH Key: deploy-key-infrastructure
Access: Private Repository
Repository-Struktur für Semaphore:
ansible-infrastructure/
├── playbooks/
│ ├── webserver-deployment.yml
│ ├── database-backup.yml
│ ├── system-maintenance.yml
│ └── security-hardening.yml
├── roles/
│ ├── nginx/
│ ├── mysql/
│ ├── monitoring/
│ └── backup/
├── inventories/
│ ├── production/
│ ├── staging/
│ └── development/
├── group_vars/
├── host_vars/
├── requirements.yml # Ansible Galaxy Dependencies
└── ansible.cfg # Ansible-Konfiguration
Environment-spezifische Branches:
Git-Repository Branches:
├── main (production-ready code)
├── staging (pre-production testing)
├── development (feature development)
└── hotfix/* (emergency fixes)
Semaphore Template-Konfiguration:
├── Production Template → main branch
├── Staging Template → staging branch
├── Development Template → development branch
└── Hotfix Template → hotfix/* pattern
Release-Management mit Git-Tags:
# Git-Repository Tagging
git tag -a v1.0.0 -m "Production Release 1.0.0"
git tag -a v1.1.0-rc1 -m "Release Candidate 1.1.0"
git push origin --tagsSemaphore Template-Konfiguration:
Template: Production Deployment
├── Repository: ansible-infrastructure
├── Branch/Tag: v1.0.0
├── Playbook: playbooks/webserver-deployment.yml
└── Description: "Stable production release"
Template: Release Candidate Testing
├── Repository: ansible-infrastructure
├── Branch/Tag: v1.1.0-rc1
├── Playbook: playbooks/webserver-deployment.yml
└── Description: "Testing new features"
Template-Parameter für Branch-Wahl:
# Template Extra Variables
target_branch: "{{ branch | default('main') }}"
deployment_environment: "{{ environment }}"
# Beispiel-Ausführung
semaphore job start --template-id 1 --extra-vars="branch=hotfix/critical-fix"Webhook-Integration:
{
"webhook_url": "https://semaphore.company.com/api/project/1/repository/1/sync",
"events": ["push", "tag"],
"branches": ["main", "staging", "development"],
"secret": "webhook-secret-token"
}Repository-Sync-Verhalten:
requirements.yml wird verarbeitetSync-Trigger über Web-Interface:
Project → Repositories → [Repository auswählen] → Sync Now
├── Force Sync: Überschreibt lokale Änderungen
├── Branch Selection: Wechsel zu anderem Branch
└── Status Display: Sync-Fortschritt und Fehlermeldungen
Periodische Updates:
Sync Schedule: "0 */6 * * *" # Alle 6 Stunden
├── Branch: main
├── Auto-update Templates: Enabled
├── Notification on Error: Enabled
└── Backup before Sync: Enabled
Änderungshistorie:
Template Execution History:
├── Job #1234: Commit a1b2c3d (v1.0.0) - Success
├── Job #1235: Commit d4e5f6g (v1.0.1) - Failed
└── Job #1236: Commit a1b2c3d (v1.0.0) - Success (Rollback)
Multi-Developer Workflows:
Schnelle Wiederherstellung:
Rollback-Szenario:
1. Fehlerhaftes Deployment mit v1.1.0
2. Template auf v1.0.0 zurücksetzen
3. Rollback-Playbook ausführen
4. System-Validation durchführen
Playbooks sind statische YAML-Definitionen für Automatisierungsaufgaben:
# webserver-deployment.yml
---
- name: Deploy Web Application
hosts: webservers
become: yes
vars:
app_version: "1.0.0"
app_port: 8080
tasks:
- name: Install application
unarchive:
src: "https://releases.company.com/app-{{ app_version }}.tar.gz"
dest: /opt/application
remote_src: yesTemplates sind konfigurierte Ausführungsumgebungen für Playbooks mit:
Template-Konfiguration:
Template Name: "Deploy Web Application"
Playbook: playbooks/webserver-deployment.yml
Inventory: production-webservers
Credentials: web-deployment-key
Extra Variables:
├── app_version: "1.2.0"
├── app_environment: "production"
├── enable_ssl: true
├── max_connections: 1000
└── deployment_user: "deploy"
Dynamische Eingaben:
# Template Extra Variables mit Platzhaltern
app_version: "{{ version | default('latest') }}"
deployment_environment: "{{ env }}"
feature_flags: "{{ features | default('') }}"
rollback_version: "{{ previous_version | default('') }}"
# Verwendung bei Job-Ausführung
version: "1.3.0"
env: "staging"
features: "new-ui,api-v2"Input-Validierung in Playbooks:
- name: Validate deployment parameters
assert:
that:
- app_version is defined
- app_version | regex_search('^\\d+\\.\\d+\\.\\d+$')
- deployment_environment in ['development', 'staging', 'production']
fail_msg: "Invalid deployment parameters provided"Basis-Template mit Variationen:
Base Template: "Application Deployment"
├── Production Variant
│ ├── Inventory: production-servers
│ ├── Variables: production-specific
│ └── Credentials: prod-deploy-key
├── Staging Variant
│ ├── Inventory: staging-servers
│ ├── Variables: staging-specific
│ └── Credentials: staging-deploy-key
└── Development Variant
├── Inventory: dev-servers
├── Variables: dev-specific
└── Credentials: dev-deploy-key
Gemeinsame Basis-Konfiguration:
# Base Template Variables
common_variables:
app_name: "web-application"
log_level: "INFO"
health_check_url: "/health"
# Environment-specific Overrides
production_variables:
<<: *common_variables
log_level: "WARN"
instance_count: 3
staging_variables:
<<: *common_variables
log_level: "DEBUG"
instance_count: 1Template-Definition:
Template Name: "Multi-Environment Deployment"
Repository: ansible-deployments
Playbook: playbooks/application-deploy.yml
Parameters:
├── target_environment (required)
│ ├── Values: [development, staging, production]
│ └── Default: development
├── application_version (required)
│ ├── Pattern: semver (x.y.z)
│ └── Default: latest
├── enable_monitoring (optional)
│ ├── Type: boolean
│ └── Default: true
└── deployment_strategy (optional)
├── Values: [rolling, blue-green, canary]
└── Default: rolling
Conditional Inventory Selection:
# Template Extra Variables
inventory_mapping:
development: "dev-servers"
staging: "staging-servers"
production: "prod-servers"
selected_inventory: "{{ inventory_mapping[target_environment] }}"Environment-spezifische Variablen:
# Environment Configuration Matrix
environment_config:
development:
instance_count: 1
resource_limits:
memory: "512Mi"
cpu: "0.5"
ssl_enabled: false
staging:
instance_count: 2
resource_limits:
memory: "1Gi"
cpu: "1.0"
ssl_enabled: true
production:
instance_count: 5
resource_limits:
memory: "2Gi"
cpu: "2.0"
ssl_enabled: true
backup_enabled: trueDeployment-Pipeline:
- name: Environment-specific deployment
include_vars: "vars/{{ target_environment }}.yml"
- name: Validate environment configuration
assert:
that:
- target_environment in ['development', 'staging', 'production']
- application_version is match('^\d+\.\d+\.\d+$')
- name: Deploy application
include_tasks: "tasks/deploy-{{ deployment_strategy }}.yml"
vars:
env_config: "{{ environment_config[target_environment] }}"Task-Tags:
- name: Install application packages
package:
name: "{{ app_packages }}"
state: present
tags:
- packages
- installation
- security-updates
- name: Configure application
template:
src: app.conf.j2
dest: /etc/app/app.conf
tags:
- configuration
- config
- name: Start application service
service:
name: "{{ app_service }}"
state: started
enabled: yes
tags:
- service
- startupSemaphore Template Settings:
Template: "Application Management"
├── Playbook: playbooks/app-management.yml
├── Tags: "configuration,service"
├── Skip Tags: "packages"
└── Description: "Update config and restart service only"
Selektive Ausführung:
# Nur Konfiguration aktualisieren
--tags "configuration"
# Installation und Service-Start
--tags "installation,service"
# Alles außer Packages
--skip-tags "packages"
# Mehrere Tag-Gruppen
--tags "configuration" --tags "service"Limit-Optionen:
# Einzelner Host
--limit "web01.company.com"
# Mehrere Hosts
--limit "web01.company.com,web02.company.com"
# Gruppe
--limit "webservers"
# Gruppenkombination
--limit "webservers:&production"
# Ausschluss
--limit "webservers:!web03.company.com"
# Pattern-Matching
--limit "web*.company.com"
# Slice-Notation
--limit "webservers[0:2]" # Erste 3 Hosts der GruppeSemaphore Template-Einstellungen:
Template: "Rolling Update"
├── Inventory: production-all
├── Limit: "webservers[0:1]"
├── Description: "Deploy to first webserver only"
└── Use Case: "Blue-Green Deployment - Phase 1"
Template: "Emergency Patch"
├── Inventory: production-all
├── Limit: "{{ target_hosts | default('all') }}"
├── Extra Variables: target_hosts
└── Description: "Apply patch to specified hosts"
Gestaffeltes Deployment:
# Rolling Deployment Strategy
- name: Phase 1 - Deploy to subset
hosts: "webservers[0:{{ (groups['webservers'] | length / 3) | int }}]"
serial: 1
- name: Phase 2 - Deploy to remaining
hosts: "webservers[{{ (groups['webservers'] | length / 3) | int + 1 }}:]"
serial: 2Template-Konfiguration:
Template: "Configuration Review"
├── Diff Mode: Enabled
├── Playbook: playbooks/system-config.yml
├── Purpose: "Show configuration changes before apply"
└── Recommendation: "Review diff output before production"
File-Änderungen:
--- /etc/nginx/nginx.conf 2024-08-15 10:30:00.000000000 +0200
+++ /tmp/nginx.conf 2024-08-15 14:45:00.000000000 +0200
@@ -15,7 +15,7 @@
server_tokens off;
# Worker processes
- worker_processes auto;
+ worker_processes 4;
# Worker connections
worker_connections 1024;Service-Status-Änderungen:
TASK [Restart nginx service] ****************************************************
--- before
+++ after
@@ -1,4 +1,4 @@
{
- "state": "stopped",
+ "state": "started",
"enabled": true
}
Review-Process:
- name: Generate configuration diff
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
backup: yes
diff: yes
check_mode: yes
register: config_diff
- name: Display changes for review
debug:
var: config_diff.diff
when: config_diff.changedCheck-Mode-Charakteristika: - Keine tatsächlichen Systemänderungen - Simulation der Playbook-Ausführung - Identifikation potentieller Änderungen - Validierung von Playbook-Logik
Semaphore Template-Settings:
Template: "Pre-Production Validation"
├── Check Mode: Enabled
├── Diff Mode: Enabled
├── Playbook: playbooks/production-deploy.yml
├── Purpose: "Validate changes before production deployment"
└── Scheduling: "Run before every production deployment"
Module-Abhängigkeiten:
# Nicht alle Module unterstützen Check-Mode vollständig
- name: Check if service exists (works in check mode)
service_facts:
- name: Restart service (limited check mode support)
service:
name: nginx
state: restarted
# May show 'changed' in check mode even without changesValidierungs-Pipeline:
- name: Validation Phase
block:
- name: Check syntax
include_tasks: validate-syntax.yml
- name: Test connectivity
ping:
- name: Validate configuration files
template:
src: "{{ item }}.j2"
dest: "/tmp/{{ item }}"
loop:
- nginx.conf
- app.conf
check_mode: yes
diff: yesAutomatisch gespeicherte Artefakte:
Job Execution #1234:
├── stdout.log # Standard-Ausgabe
├── stderr.log # Fehler-Ausgabe
├── ansible-facts.json # Gesammelte Host-Facts
├── job-summary.json # Execution-Summary
├── inventory-snapshot.yml # Verwendetes Inventory
└── extra-vars.json # Template-Variablen
Aufbewahrungsrichtlinien:
Retention Configuration:
├── Log Retention: 90 Tage
├── Artefakt Retention: 30 Tage
├── Failed Jobs: 180 Tage (extended)
├── Critical Templates: 365 Tage
└── Cleanup Schedule: Täglich um 02:00 Uhr
Playbook-Integration:
- name: Generate deployment report
template:
src: deployment-report.j2
dest: "/tmp/deployment-{{ ansible_date_time.epoch }}.html"
delegate_to: localhost
- name: Store configuration backup
fetch:
src: "/etc/{{ item }}"
dest: "./backups/{{ inventory_hostname }}/{{ item }}"
flat: yes
loop:
- nginx.conf
- ssl/certificates.crtMulti-Level Logging:
Job #1234 - Deploy Web Application
├── Job-Level Logs
│ ├── Pre-execution validation
│ ├── Inventory loading
│ ├── Credential preparation
│ └── Post-execution cleanup
├── Playbook-Level Logs
│ ├── Play execution order
│ ├── Host selection
│ └── Variable resolution
└── Task-Level Logs
├── Individual task execution
├── Module parameters
├── Return values
└── Error details
Semaphore Logging-Konfiguration:
Template: "Detailed Application Deployment"
├── Verbose Level: -vvv
├── Log stdout: Enabled
├── Log stderr: Enabled
├── Log ansible facts: Enabled
└── Debug logging: Enabled
Ansible Verbosity-Levels:
-v : Basic output
-vv : More detailed output
-vvv : Debug-level output with execution details
-vvvv : Maximum verbosity with connection debugging
Live-Log-Stream:
Job Execution Interface:
├── Real-time stdout stream
├── Color-coded output
├── Expandable task details
├── Error highlighting
├── Progress indicators
└── Execution timeline
Log-Analysis-Features:
Log Viewer Capabilities:
├── Search functionality
├── Filter by log level
├── Filter by host
├── Filter by task
├── Download raw logs
└── Export filtered results
Automatische Bereinigung:
# Ansible no_log directive
- name: Set database password
set_fact:
db_password: "{{ vault_db_password }}"
no_log: true
- name: Configure database connection
template:
src: database.conf.j2
dest: /etc/app/database.conf
no_log: true
when: db_password is definedSemaphore Credential-Protection:
Log Output Masking:
├── Password fields: ********
├── SSH private keys: [PROTECTED]
├── API tokens: [MASKED]
├── Certificate data: [REDACTED]
└── Custom sensitive vars: [HIDDEN]
Template-Security-Settings:
Template: "Secure Database Setup"
├── Hide sensitive data: Enabled
├── Mask credentials: Enabled
├── Log level: Standard (no debug)
├── Retain logs: 30 days
└── Access restriction: Admins only
Verfügbare Export-Optionen:
Export Capabilities:
├── Individual job logs (TXT, JSON)
├── Multiple job comparison (CSV)
├── Execution reports (HTML, PDF)
├── Compliance reports (XML, JSON)
├── Custom artefakt bundles (ZIP)
└── API-based exports (REST)
Integration in CI/CD:
# Post-deployment reporting
- name: Generate deployment summary
uri:
url: "{{ semaphore_api_url }}/project/{{ project_id }}/tasks/{{ task_id }}/output"
headers:
Authorization: "Bearer {{ api_token }}"
method: GET
register: deployment_logs
delegate_to: localhost
- name: Store in artifact repository
copy:
content: "{{ deployment_logs.json | to_nice_json }}"
dest: "./artifacts/deployment-{{ ansible_date_time.date }}.json"
delegate_to: localhostAudit-Trail-Generierung:
Compliance Report Contents:
├── Execution metadata
│ ├── User authentication
│ ├── Timestamp information
│ ├── Template configuration
│ └── Inventory details
├── Security validation
│ ├── Credential usage
│ ├── Permission verification
│ ├── Network access logs
│ └── Change documentation
└── Result documentation
├── Success/failure status
├── Applied changes
├── System impacts
└── Rollback capabilities
Hierarchische Speicherung:
/semaphore/artifacts/
├── projects/
│ ├── web-application/
│ │ ├── 2024/08/
│ │ │ ├── job-1234/
│ │ │ └── job-1235/
│ │ └── reports/
│ │ ├── weekly/
│ │ └── monthly/
│ └── infrastructure/
│ └── 2024/08/
└── system/
├── backups/
└── compliance/
Lifecycle-Management:
# Artefakt-Cleanup-Strategy
cleanup_policies:
job_logs:
retention_days: 90
cleanup_schedule: "0 2 * * 0" # Weekly
failed_jobs:
retention_days: 180
priority: high
compliance_reports:
retention_days: 2555 # 7 years
archive_location: "/backup/compliance"
debug_artifacts:
retention_days: 14
size_limit: "1GB"