
Une fois votre rôle stable et testé, l’étape finale est la publication : tag Git semver, CHANGELOG mis à jour, push sur Ansible Galaxy (public) ou Automation Hub (privé). Cette page couvre le workflow complet, de l’écriture du CHANGELOG à la release automatique via CI/CD.
Ce que vous allez apprendre
Section intitulée « Ce que vous allez apprendre »- Workflow Git semver : MAJOR.MINOR.PATCH.
- Format
CHANGELOG.mdKeep a Changelog. - Publication sur Ansible Galaxy (méthodes webhook GitHub et CLI).
- Automation Hub privé pour entreprise.
- Release automatique via CI/CD (GitHub Actions ou GitLab CI).
Convention semver pour rôles Ansible
Section intitulée « Convention semver pour rôles Ansible »MAJOR.MINOR.PATCH│ │ └─ bugfix rétrocompatible (1.0.0 → 1.0.1)│ └─────── nouvelle feature rétrocompatible (1.0.0 → 1.1.0)└───────────── breaking change (1.0.0 → 2.0.0)Règles :
- MAJOR : variable renommée, structure cassée, suppression d’option.
- MINOR : nouvelle variable optionnelle, nouvelle plateforme supportée.
- PATCH : bugfix, typo, optimisation interne.
Le fichier CHANGELOG.md
Section intitulée « Le fichier CHANGELOG.md »Format Keep a Changelog (keepachangelog.com) :
# Changelog — rôle webserver
## [1.2.0] - 2026-04-26
### Added- Support multi-distribution (RHEL, AlmaLinux, Debian via vars/<os_family>.yml)- Variable `webserver_worker_processes` configurable- Validation argument_specs.yml
### Changed- Module `package` (agnostique) au lieu de `dnf` direct- Templates Jinja réorganisés pour lisibilité
### Fixed- Idempotence handlers (Reload nginx déclenché 2× résolu)
## [1.1.0] - 2026-03-15
### Added- Handlers Restart nginx et Reload nginx- Validate sur le template nginx.conf
## [1.0.0] - 2026-02-01
### Added- Premier release stable- Installation nginx, démarrage, ouverture firewall HTTPSections standard : Added, Changed, Deprecated, Removed, Fixed, Security. Toutes optionnelles selon le contenu du release.
Workflow Git semver
Section intitulée « Workflow Git semver »# 1. Mettre à jour CHANGELOG.mdvim CHANGELOG.md# Ajouter section ## [1.2.0] - 2026-04-26
# 2. Tester (Molecule + ansible-lint)molecule testansible-lint --profile=production roles/webserver/
# 3. Commitgit add CHANGELOG.mdgit commit -m "release: v1.2.0"
# 4. Tag semvergit tag -a v1.2.0 -m "Release v1.2.0 - Multi-distro support"
# 5. Pushgit push origin main --tagsNote : tag avec préfixe v (v1.2.0, pas 1.2.0). Convention quasi-universelle.
Publication sur Ansible Galaxy
Section intitulée « Publication sur Ansible Galaxy »Prérequis
Section intitulée « Prérequis »- Compte sur galaxy.ansible.com lié à GitHub.
- Token API depuis votre profil → API Token.
meta/main.ymlcomplet avecgalaxy_info.
Méthode 1 — Via GitHub Webhook (rôles)
Section intitulée « Méthode 1 — Via GitHub Webhook (rôles) »- Sur Galaxy, My Content → Add Content → Import Role from GitHub.
- Sélectionner le repo
stephrobert/ansible-role-webserver. - Galaxy importe automatiquement à chaque nouveau tag Git semver.
Pas besoin de CLI — workflow GitOps natif.
Méthode 2 — CLI (collections)
Section intitulée « Méthode 2 — CLI (collections) »# Build la collection (génère .tar.gz)cd path/to/collection/ansible-galaxy collection build
# Publier sur Galaxyansible-galaxy collection publish \ stephrobert-networking-1.0.0.tar.gz \ --api-key=$GALAXY_TOKENToken disponible dans variables d’env CI/CD (ANSIBLE_GALAXY_TOKEN).
Automation Hub privé (entreprise)
Section intitulée « Automation Hub privé (entreprise) »Pour les entreprises qui ne veulent pas exposer leurs rôles publiquement :
# ansible.cfg[galaxy]server_list = corporate_hub
[galaxy_server.corporate_hub]url = https://hub.corp.example.com/api/automation-hub/token = <token>Avantages Automation Hub :
- Privé : code interne non exposé sur Galaxy public.
- Certifié Red Hat : collections supportées commercialement.
- Allow-list : votre équipe sécurité valide chaque collection avant publication.
- Mirror : réplique Galaxy public pour usage offline.
Release automatique via CI/CD
Section intitulée « Release automatique via CI/CD »GitHub Actions
Section intitulée « GitHub Actions »name: Release to Galaxy
on: push: tags: ['v*.*.*']
jobs: release: runs-on: ubuntu-24.04 permissions: contents: read steps: - uses: actions/checkout@<SHA> with: persist-credentials: false
- name: Build and publish collection run: | ansible-galaxy collection build ansible-galaxy collection publish *.tar.gz \ --api-key=${{ secrets.GALAXY_TOKEN }}Token GitHub Secrets = GALAXY_TOKEN configuré dans Settings → Secrets.
GitLab CI
Section intitulée « GitLab CI »# .gitlab-ci.yml (extrait)release: stage: release rules: - if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/ script: - ansible-galaxy collection build - ansible-galaxy collection publish *.tar.gz --api-key=$GALAXY_TOKENToken GitLab Variables = GALAXY_TOKEN (Masked + Protected).
Communication post-release
Section intitulée « Communication post-release »README.md à jour
Section intitulée « README.md à jour »Variables nouvelles, exemples mis à jour. Pas de drift entre code et doc.
Release notes GitHub
Section intitulée « Release notes GitHub »Sur GitHub, Releases → Create a new release depuis le tag. Reprendre le contenu du CHANGELOG section correspondante.
Migration guide pour breaking change
Section intitulée « Migration guide pour breaking change »Si MAJOR bump : ajouter un fichier MIGRATION.md qui détaille les changements et le pattern de migration pour les utilisateurs.
# Migration guide
## v1.x → v2.0
### Variable renommée
`webserver_port` → `webserver_listen_port`
Fix automatique :
```bashsed -i 's/webserver_port/webserver_listen_port/g' playbooks/*.yml## Pratiquer dans le lab
Cette page a un **lab d'accompagnement** : **`labs/galaxy/versionner-publier/`** dans[stephrobert/ansible-training](https://github.com/stephrobert/ansible-training).
Le lab fournit `CHANGELOG.md` (3 versions semver) + `PUBLISH.md` (workflow complet). **7 tests structure** validés.
```bashcd ~/Projets/ansible-training/labs/galaxy/versionner-publier/
cat CHANGELOG.mdcat PUBLISH.mdpytest -v challenge/tests/ # 7 testsPièges courants
Section intitulée « Pièges courants »| Symptôme | Cause | Fix |
|---|---|---|
| Tag pushé mais Galaxy n’importe pas | Webhook GitHub désactivé | Galaxy → Imports → re-trigger manuel |
ansible-galaxy collection publish échoue | Token expiré | Régénérer sur galaxy.ansible.com |
| Breaking change non signalé | Pas de bump MAJOR | Toujours bump MAJOR + MIGRATION.md |
| Versions incohérentes entre code et tag | Pas de single source of truth | Mettre la version dans meta/main.yml ET tag Git |
| Release sur Galaxy privée mais code sur GitHub public | Configuration mixte | Cohérent : code privé → Hub privé, code public → Galaxy public |
À retenir
Section intitulée « À retenir »- Semver MAJOR.MINOR.PATCH = breaking, feature, bugfix.
- Tag Git
v1.2.0+ CHANGELOG.md Keep a Changelog. - Publication Galaxy : webhook GitHub (rôles) ou CLI (collections).
- Automation Hub privé pour entreprise (privé, certifié Red Hat).
- Release automatique via CI/CD (GitHub Actions / GitLab CI) sur tag.
- MIGRATION.md mandatory sur tout breaking change.