Il y a 8 ans -
Temps de lecture 8 minutes
Une VM moderne pour IE avec Vagrant
Nous développons une application Web destinée à des utilisateurs corporate sous Internet Explorer 9. Nos Product Owners utilisent Windows et IE 11, nous développons sous Mac OS X, et les serveurs tournent sous Linux.
Dans cet environnement hétérogène, nous utilisions déjà Vagrant pour gérer plusieurs VM Linux : intégration continue, bases de données, conteneur Web.
Vagrant est une solution libre et open source qui permet de créer des VM, et de s’y connecter en quelques lignes de commandes. Par exemple pour la dernière version d’Ubuntu :
[java]vagrant init ubuntu/trusty64
vagrant up
vagrant ssh
[/java]
D’autres VM avec plusieurs versions de Windows et d’IE ont été mises à disposition gratuitement par Microsoft, pour les développeurs Web, avec une licence temporaire pour un usage de test. On peut théoriquement les utiliser aussi facilement :
[java]vagrant box add win7-ie11 http://aka.ms/vagrant-win7-ie11
vagrant init win7-ie11
vagrant up
vagrant rdp
[/java]
En pratique c’est plus compliqué, car aucun accès à distance n’est configuré par défaut. Pas de SSH, et pas de RDP (le protocole de Microsoft).
- Le premier symptôme est un timeout, au moment où Vagrant essaie de se connecter à la VM pour vérifier qu’elle est bien démarrée
- On ne peut pas non plus manipuler notre VM avec Vagrant, pour l’éteindre ou pour la redémarrer
Nous allons voir comment personnaliser une box Microsoft pour corriger ces problèmes, et comment la redistribuer.
Pré-requis
- Vagrant 1.7 minimum
- VirtualBox
- Un gestionnaire de téléchargement, par exemple la commande
wget
- Une bonne connexion internet, ou bien quelques heures de patience, pour télécharger les VM
- Un client Microsoft Remote Desktop
Personnalisation
Téléchargez la box Vagrant : wget -c http://aka.ms/vagrant-win7-ie11
Cette commande peut être relancée pour reprendre le téléchargement en cas d’interruption. Ca peut être très long.
Créez votre fichier Vagrantfile :
[java]Vagrant.configure(2) do |config|
config.vm.guest = :windows
# Configuration de winrm, qui rend la VM scriptable depuis
# l’extérieur.
config.vm.communicator = "winrm"
# Identifiants pour que Vagrant puisse commander la VM
config.winrm.username = "IEUser"
config.winrm.password = "Passw0rd!"
# Ouverture du port réseau de winrm
config.vm.network :forwarded_port, guest: 5985, host: 59851,
id: "winrm", auto_correct:true
# Ouverture du port du remote desktop protocol
config.vm.network :forwarded_port, guest: 3389, host: 33891,
id: "rdp", auto_correct:true
# Chemin de la box qui sera importée au premier démarrage
config.vm.box_url = "file://vagrant-win7-ie11"
# Timeout rapide (30 s) au premier démarrage
config.vm.boot_timeout = 30
# Nom de la box
config.vm.box = "win7-ie11"
# Configuration spécifique à la techno de virtualisation
# utilisée
config.vm.provider "virtualbox" do |vb|
# Afficher l’interface graphique Windows
vb.gui = true
# Mémoire vive
vb.memory = "1024"
# Presse-papiers partagé
vb.customize ["modifyvm", :id, "–clipboard", "bidirectional"]
end
end
[/java]
Premier lancement
Lancez la commande vagrant up
pour lancer la VM :
[java]$ vagrant up
Bringing machine ‘default’ up with ‘virtualbox’ provider…
==> default: Importing base box ‘win7-ie11’…
==> default: Matching MAC address for NAT networking…
==> default: Setting the name of the VM: vagrant-win-ie_default_1427923643091_51251
==> default: Clearing any previously set network interfaces…
==> default: Preparing network interfaces based on configuration…
default: Adapter 1: nat
==> default: Forwarding ports…
default: 5985 => 59851 (adapter 1)
default: 3389 => 33891 (adapter 1)
default: 22 => 2222 (adapter 1)
==> default: Running ‘pre-boot’ VM customizations…
[…]
[/java]
Vagrant affiche un message de timeout. Pas la peine d’augmenter la valeur dans le Vagrantfile, car il utilise WinRM pour accéder à la machine, et ce n’est pas encore autorisé :
[java][…]
==> default: Booting VM…
==> default: Waiting for machine to boot. This may take a few minutes…
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.
If you’re using a custom box, make sure that networking is properly
working and you’re able to connect to the machine. It is a common
problem that networking isn’t setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
[/java]
Pourtant elle est démarrée, puisque nous voyons l’interface graphique de Windows :
Profitez-en pour configurer le réseau Windows en choisissant ‘home network’.
La VM n’accepte pas encore les commandes Vagrant, par exemple vagrant halt
:
[java]$ vagrant halt
==> default: Attempting graceful shutdown of VM…
^C==> default: Waiting for cleanup before exiting…
^C==> default: Exiting immediately, without cleanup!
[/java]
Pour régler ça, ouvrez un terminal Windows en tant qu’administrateur dans la VM et lancez ces commandes :
[java]winrm quickconfig -q
powershell Set-Item WSMan:\localhost\Service\AllowUnencrypted -Value True
powershell Set-Item WSMan:\localhost\Service\Auth\Basic -Value True[/java]
Refaites un vagrant halt
, ça doit marcher du premier coup.
NB : si la syntaxe de PowerShell vous rebute, vous pouvez aussi configurer WinRM avec la commande winrm
:
[java]winrm quickconfig -q
winrm set winrm/config/service @{AllowUnencrypted="true"}
winrm set winrm/config/service/Auth @{Basic="true"}[/java]
Finalisation
Passez vb.gui
à false
pour lancer la VM sans affichage (headless), et le timeout à 5 minutes pour lui laisser le temps de démarrer (sur mon MacBook Pro 2015, elle prend 2-3 minutes) :
[java][…]
# Timeout suffisant pour le démarrage de Windows
config.vm.boot_timeout = 300
# Configuration spécifique à la techno de
# virtualisation utilisée
config.vm.provider "virtualbox" do |vb|
# Démarrage headless
vb.gui = false
[…]
[/java]
Refaites un vagrant up
pour tester le démarrage de la VM. Il ne doit pas y avoir de timeout :
[java]$ vagrant up
Bringing machine ‘default’ up with ‘virtualbox’ provider…
==> default: Clearing any previously set forwarded ports…
==> default: Clearing any previously set network interfaces…
==> default: Preparing network interfaces based on configuration…
default: Adapter 1: nat
==> default: Forwarding ports…
default: 5985 => 59851 (adapter 1)
default: 3389 => 33891 (adapter 1)
default: 22 => 2222 (adapter 1)
==> default: Running ‘pre-boot’ VM customizations…
==> default: Booting VM…
==> default: Waiting for machine to boot. This may take a few minutes…
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM…
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
[…]
==> default: Mounting shared folders…
default: /vagrant => /home/cp/WORKSPACES/vagrant-win-ie
[/java]
Pour valider l’installation, accédez à la VM en local avec un client RDP grâce à la commande vagrant rdp
(identifiants par défaut : IEUser/Passw0rd!).
Distribution
Maintenant que la VM est finalisée, preparez un paquet pour la box :
[java]$ vagrant package
==> default: Clearing any previously set forwarded ports…
==> default: Exporting VM…
==> default: Compressing package to: /[…]/vagrant-win-ie/package.box
$ mv package.box vagrant-win7-ie11-xebia.box
[/java]
Copiez ce fichier sur un serveur accessible à votre équipe, comme un serveur Web :
[java]$ scp vagrant-win7-ie11-xebia.box un-serveur.xebia.com:/tmp
$ ssh un-serveur.xebia.com
user@un-serveur.xebia$ mv /tmp/vagrant-win7-ie11-xebia.box /var/www
[/java]
Configurez l’URL d’accès à ce fichier dans le Vagrantfile :
[java][…]
# Chemin de la box qui sera importée au premier démarrage
config.vm.box_url = "http://un-serveur.xebia.com/vagrant-win7-ie11-xebia.box"
# Nom de la box
config.vm.box = "win7-ie11-xebia"
[…]
[/java]
Déployez votre Vagrantfile sur une repository accessible à votre équipe, avec Git par exemple :
[java]git init
git remote add http://un-serveur.xebia.com/vagrant-win7-ie-xebia.git
git commit -a -m ‘Initial version: custom IE VM’
git push
[/java]
Utilisation
Clonez la repository où vous avez déployé le Vagrantfile :
[java]git clone http://un-serveur.xebia.com/vagrant-win7-ie-xebia.git
[/java]
Allez dans le nouveau répertoire, et faites un vagrant up
pour lancer la VM. Vagrant va télécharger la box repackagée et cette fois-ci, il ne doit pas y avoir de timeout.
Voilà ! Vous pouvez directement manipuler la VM avec Vagrant : vagrant halt
, vagrant reload
, etc.
Vous pouvez vous y connecter en local avec un vagrant rdp
, ou à distance sur le port 33891 avec un client remote desktop.
Références
Cet article est une synthèse de plusieurs sources sur Internet :
- La page virtualisation sur modern.ie, qui fournit les VM pour VirtualBox
- Windows Boxes for Vagrant Courtesy of Modern.ie, qui fournit les VM ‘brutes’ pour Vagrant
- La page Vagrantfile WinRM Settings, qui donne les lignes de commandes PowerShell pour débloquer la connection par WinRM
Logiciels :
- Clients RDP :
- Linux :
- Mac OS X : Client Connexion Bureau à Distance
- Windows :
mstsc.exe
Commentaire
4 réponses pour " Une VM moderne pour IE avec Vagrant "
Published by skydjol , Il y a 8 ans
il me semble qu’il manque un « end » dans le Vagrantfile.
config.vm.provider « virtualbox » do |vb|
# Afficher l’interface graphique Windows
vb.gui = true
# Mémoire vive
vb.memory = « 1024 »
# Presse-papiers partagé
vb.customize [« modifyvm », :id, « –clipboard », « bidirectional »]
end
end
Published by Christophe Pelé , Il y a 8 ans
Bien vu. C’est corrigé.
Published by JLM , Il y a 8 ans
Bonjour, merci pour cet article bien pratique. Je ne comprends pas pourquoi la VM met tant de temps à être dispo lors du vagrant up (après avoir configuré winrm). On peut voir dans VBox que Windows est démarré très vite (30 secondes). Que se passe-t-il ensuite qui prenne 1 à plusieurs minutes ? :-/
Published by Christophe Pelé , Il y a 8 ans
En démarrant avec
VAGRANT_LOG=info vagrant up
, on peut avoir plus d’infos sur ce qui se passe :INFO subprocess: Starting process: ["/usr/bin/VBoxManage", "showvminfo", "f0c8ac3a-8662-4eb7-9ffc-abadfcf7162e", "--machinereadable"]
INFO subprocess: Starting process: ["/usr/bin/VBoxManage", "showvminfo", "f0c8ac3a-8662-4eb7-9ffc-abadfcf7162e", "--machinereadable"]
INFO subprocess: Starting process: ["/usr/bin/VBoxManage", "showvminfo", "f0c8ac3a-8662-4eb7-9ffc-abadfcf7162e", "--machinereadable"]
[...]
INFO subprocess: Starting process: ["/usr/bin/VBoxManage", "showvminfo", "f0c8ac3a-8662-4eb7-9ffc-abadfcf7162e", "--machinereadable"]
INFO winrm: WinRM is ready!
INFO interface: output: Machine booted and ready!
INFO interface: output: ==> default: Machine booted and ready!
Apparemment, Vagrant attend que WinRM soit prêt.
Published by JLM , Il y a 7 ans
Hello,
en fait, le service winrm est configuré pour démarrer en « Automatic (delayed start) ».
On peut le voir via l’interface des services (commande rapide : services.msc). En le passant tout simplement à « Automatique », la liaison vagrant->windows est bien plus rapide.
@+
Published by Clément , Il y a 5 ans
Pour éviter les manipulations à la souris, on peut exploiter le service openssh qui tourne déjà sur la VM, avec un shell minimaliste. Ça suffit pour lancer cmd.exe ou powershell et configurer WinRM.