
Ansible n’est pas qu’un outil Linux — il pilote très bien Windows Server 2016+, Windows 10/11, à condition de choisir le bon transport de connexion : WinRM (historique, intégré AD) ou OpenSSH (moderne, plus simple).
Cette page donne les prérequis, le choix entre les deux protocoles, le premier win_ping, et la cartographie des collections Ansible Windows.
Ce que vous allez apprendre
Section intitulée « Ce que vous allez apprendre »- Choisir entre WinRM et OpenSSH selon votre contexte.
- Activer WinRM ou OpenSSH côté Windows.
- Configurer un inventaire Ansible pour cibler Windows.
- Tester la connexion avec
win_ping. - Identifier les modules
win_*essentiels.
Prérequis
Section intitulée « Prérequis »| Côté | Exigences |
|---|---|
| Hôte Windows | Windows Server 2016+ ou Windows 10/11, PowerShell 5.1+, .NET 4.0+ |
| Contrôleur Ansible | Linux/macOS avec Python 3.10+, collections ansible.windows et community.windows |
ansible-galaxy collection install ansible.windows community.windowsWinRM vs OpenSSH — tableau de décision
Section intitulée « WinRM vs OpenSSH — tableau de décision »| Critère | WinRM | OpenSSH |
|---|---|---|
| Installation | Natif Windows | Optionnel à activer |
| Configuration | Complexe (HTTPS, ACL, certificats) | Simple |
| Port | 5985 (HTTP), 5986 (HTTPS) | 22 |
| Authentification | Basic, NTLM, Kerberos, CredSSP | Mot de passe, clé SSH, GSSAPI |
| Compatibilité modules | 100% des modules win_* | Partielle, certains modules limités |
| Active Directory | Intégration native | Moins intégré |
| Cas d’usage | Entreprise + AD | Lab, projet rapide, Windows moderne |
Règle pragmatique : WinRM si vous êtes en environnement AD avec Kerberos ou si vous avez besoin de tous les modules. OpenSSH sur Windows 10/11 ou Server 2019+ pour un setup léger.
Activer WinRM côté Windows
Section intitulée « Activer WinRM côté Windows »Sur la machine Windows, ouvrir PowerShell en administrateur :
Enable-PSRemoting -ForceCela : configure un listener HTTP sur 5985, démarre le service WinRM, ouvre le pare-feu. Pour la prod, ajouter un listener HTTPS sur 5986 (certificat requis).
Vérifier :
winrm enumerate winrm/config/ListenerActiver OpenSSH côté Windows
Section intitulée « Activer OpenSSH côté Windows »Sur Windows 10/11 ou Server 2019+ :
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0Start-Service sshdSet-Service -Name sshd -StartupType 'Automatic'Forcer PowerShell comme shell par défaut (recommandé pour Ansible) :
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell ` -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -ForceInventaire Ansible — exemple WinRM
Section intitulée « Inventaire Ansible — exemple WinRM »[windows]192.168.1.10
[windows:vars]ansible_connection=winrmansible_user=Administratoransible_password=MotDePasseSecuriseansible_port=5986ansible_winrm_transport=basicansible_winrm_server_cert_validation=ignoreansible_winrm_server_cert_validation=ignore → uniquement pour le lab. En prod, déployer un certificat de confiance et passer à validate.
Inventaire Ansible — exemple OpenSSH
Section intitulée « Inventaire Ansible — exemple OpenSSH »[windows]192.168.1.10
[windows:vars]ansible_connection=sshansible_user=ansibleuseransible_shell_type=powershellansible_ssh_common_args='-o StrictHostKeyChecking=no'ansible_shell_type=powershell est critique — sans ça, Ansible essaie d’envoyer du bash et échoue silencieusement.
Premier test — win_ping
Section intitulée « Premier test — win_ping »ansible windows -i inventory.ini -m win_pingSortie attendue :
192.168.1.10 | SUCCESS => { "changed": false, "ping": "pong"}Si échec : vérifier le pare-feu Windows, le service WinRM/sshd, et l’authentification (mot de passe ou clé).
Cartographie des modules win_*
Section intitulée « Cartographie des modules win_* »| Domaine | Modules | Usage |
|---|---|---|
| Utilisateurs | win_user, win_group | Comptes et groupes locaux |
| Fichiers | win_copy, win_file, win_template | Copie, permissions, templates |
| Services | win_service | Démarrer, arrêter, configurer |
| Registre | win_regedit, win_reg_stat | Lecture/écriture du registre |
| Rôles Windows | win_feature | IIS, Hyper-V, Active Directory |
| Mises à jour | win_updates | Patches Windows Update |
| Pare-feu | win_firewall_rule | Règles entrantes/sortantes |
| Tâches planifiées | win_scheduled_task | Cron Windows |
| Exécution | win_command, win_shell | Équivalent command / shell |
| Inspection | win_stat | Équivalent stat |
Le préfixe win_ est votre repère : tous les modules win_* sont dédiés Windows et envoient du PowerShell sous le capot.
Collection community.windows — pour aller plus loin
Section intitulée « Collection community.windows — pour aller plus loin »| Domaine | Module | Usage |
|---|---|---|
| Chocolatey | win_chocolatey | Installation de paquets via Chocolatey |
| PowerShell | win_psmodule | Modules PSGallery |
| PATH | win_path | Ajout/retrait dans PATH |
| Raccourcis | win_shortcut | Fichiers .lnk |
| Stratégies | win_account_policy, win_audit_policy_system | Audit, mots de passe |
Pièges courants
Section intitulée « Pièges courants »| Symptôme | Cause | Fix |
|---|---|---|
win_ping timeout | Pare-feu ou service WinRM/sshd arrêté | Vérifier Get-Service WinRM ou Get-Service sshd |
Authentication failure | Mauvais user/password ou Kerberos non configuré | Tester avec basic avant Kerberos |
| OpenSSH fonctionne en CLI mais pas via Ansible | ansible_shell_type non défini | Ajouter ansible_shell_type=powershell |
| Certains modules échouent en SSH | Modules nécessitant CredSSP/double-hop | Repasser à WinRM avec negotiate ou kerberos |
Lenteur sur win_copy (gros fichiers) | Limitation WinRM connue | Préférer OpenSSH (scp natif) |
À retenir
Section intitulée « À retenir »- WinRM = entreprise + AD + tous les modules. OpenSSH = lab + Windows moderne + simplicité.
ansible-galaxy collection install ansible.windows community.windows= prérequis.win_ping= test d’or pour valider la connexion.- Préfixe
win_sur tous les modules Windows. ansible_shell_type=powershellindispensable en mode SSH.