{"id":1707,"date":"2021-09-23T15:24:58","date_gmt":"2021-09-23T14:24:58","guid":{"rendered":"http:\/\/ve2cuy.com\/420-3c3\/?page_id=1707"},"modified":"2024-03-18T15:37:30","modified_gmt":"2024-03-18T15:37:30","slug":"vagrant-automatisation-de-la-creation-des-vm","status":"publish","type":"page","link":"https:\/\/ve2cuy.com\/420-21e\/index.php\/vagrant-automatisation-de-la-creation-des-vm\/","title":{"rendered":"Vagrant &#8211; Automatisation de la cr\u00e9ation des VM"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1 &#8211; Installation de vagrant<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.vagrantup.com\/downloads\">Downloads | Vagrant by HashiCorp (vagrantup.com)<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2 &#8211; Cr\u00e9ation d&rsquo;un playbook Vagrant &#8211; Fichier Vagrantfile<\/h2>\n\n\n\n<p>Dans un r\u00e9pertoire vide, cr\u00e9er un fichier nomm\u00e9 &lsquo;Vagrantfile&rsquo; avec le contenu suivant:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Ficher: Vagrantfile\n# Auteur: Alain Boudreault\n# Date:   2021.10.30\n# ---------------------------------------------------------------\n# Description: Mise en place de trois (3) VM Ubuntu,\n#              dans le but de tester des cl\u00e9s priv\u00e9es\/publiques\n# ---------------------------------------------------------------\nVagrant.configure(\"2\") do |config|\n    numberSrv=3\n    # Serveurs de tests pour les cl\u00e9s RSA\n    (1..numberSrv).each do |i|\n      config.vm.define \"CFG-serveur-0#{i}\" do |knode|\n        # D\u00e9sactiver le stockage li\u00e9 avec l'h\u00f4te.\n        knode.vm.synced_folder '.', '\/vagrant', disabled: true\n        # Renseigner la 'box' \u00e0 utiliser\n        knode.vm.box = \"ubuntu\/focal64\"\n        knode.vm.hostname = \"mon-serveur-0#{i}\"\n        # D\u00e9finition du type d'acc\u00e8s r\u00e9seau\n        # R\u00e9f\u00e9rence: https:\/\/www.vagrantup.com\/docs\/networking\n        knode.vm.network \"private_network\", ip: \"192.168.56.10#{i}\"\n        # config.vm.network \"public_network\"\n        # config.vm.network \"public_network\", ip: \"192.168.0.17\"\n        # config.vm.network \"public_network\", bridge: \"en1: Wi-Fi (AirPort)\"\n        # Utiliser un hyperviseur pour cr\u00e9er\/d\u00e9marrer les VM\n        knode.vm.provider \"virtualbox\" do |v|\n         v.name = \"VM-Serveur-0#{i}\"\n          v.memory = 1024\n          v.cpus = 1\n        end\n        # Activation du ssh hors vagrant.\n        # Note: Par d\u00e9faut, l'acc\u00e8s ssh est d\u00e9sactiv\u00e9 dans les BOX Vagrant.\n        config.vm.provision \"shell\", inline: &lt;&lt;-SHELL\n          # Activer les connexions ssh dans le fichier \/etc\/ssh\/sshd_config\n          sed -i 's\/ChallengeResponseAuthentication no\/ChallengeResponseAuthentication yes\/g' \/etc\/ssh\/sshd_config\n          service ssh restart\n        SHELL\n      end\n    end\n  end<\/pre>\n\n\n\n<p><strong><span class=\"has-inline-color has-vivid-red-color\">NOTE<\/span><\/strong>:  Les fichiers Vagrantfile sont programm\u00e9 en utilisant le langage <a href=\"https:\/\/www.ruby-lang.org\/en\/\">Ruby<\/a>. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3 &#8211; D\u00e9marrage des VM<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Dans le r\u00e9pertoire qui contient le fichier \"Vagrantfile\"\n$ vagrant up\n\n# Afficher les VM\n$ vagrant status<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4 &#8211; Connexion \u00e0 une VM<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ vagrant ssh nom-de-config-de-la-vm. # Voir: config.vm.define \"CFG-serveur-0#{i}\" do\n$ vagrant ssh CFG-serveur-01\n\n# Ou bien (Parce que ssh a \u00e9t\u00e9 activ\u00e9 dans le script)\n\n$ ssh vagrant@192.168.56.101\n# Le mot de passe est vagrant<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">5 &#8211; Shutdown des VM<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ vagrant halt<\/pre>\n\n\n\n<p>6 &#8211; Suppression des VM<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Note: -f = effacer sans confirmation\n$ vagrant destroy -f<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><a href=\"https:\/\/www.vagrantup.com\/docs\">R\u00e9f\u00e9rence Vagrant<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1 &#8211; Installation de vagrant Downloads | Vagrant by HashiCorp (vagrantup.com) 2 &#8211; Cr\u00e9ation d&rsquo;un playbook Vagrant &#8211; Fichier Vagrantfile Dans un r\u00e9pertoire vide, cr\u00e9er un fichier nomm\u00e9 &lsquo;Vagrantfile&rsquo; avec le contenu suivant: NOTE: Les fichiers Vagrantfile sont programm\u00e9 en utilisant le langage Ruby. 3 &#8211; D\u00e9marrage des VM 4 &#8211; Connexion \u00e0 une VM [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1707","page","type-page","status-publish","hentry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Alain","author_link":"https:\/\/ve2cuy.com\/420-21e\/index.php\/author\/alain\/"},"uagb_comment_info":0,"uagb_excerpt":"1 &#8211; Installation de vagrant Downloads | Vagrant by HashiCorp (vagrantup.com) 2 &#8211; Cr\u00e9ation d&rsquo;un playbook Vagrant &#8211; Fichier Vagrantfile Dans un r\u00e9pertoire vide, cr\u00e9er un fichier nomm\u00e9 &lsquo;Vagrantfile&rsquo; avec le contenu suivant: NOTE: Les fichiers Vagrantfile sont programm\u00e9 en utilisant le langage Ruby. 3 &#8211; D\u00e9marrage des VM 4 &#8211; Connexion \u00e0 une VM&hellip;","_links":{"self":[{"href":"https:\/\/ve2cuy.com\/420-21e\/index.php\/wp-json\/wp\/v2\/pages\/1707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ve2cuy.com\/420-21e\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ve2cuy.com\/420-21e\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ve2cuy.com\/420-21e\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ve2cuy.com\/420-21e\/index.php\/wp-json\/wp\/v2\/comments?post=1707"}],"version-history":[{"count":3,"href":"https:\/\/ve2cuy.com\/420-21e\/index.php\/wp-json\/wp\/v2\/pages\/1707\/revisions"}],"predecessor-version":[{"id":2287,"href":"https:\/\/ve2cuy.com\/420-21e\/index.php\/wp-json\/wp\/v2\/pages\/1707\/revisions\/2287"}],"wp:attachment":[{"href":"https:\/\/ve2cuy.com\/420-21e\/index.php\/wp-json\/wp\/v2\/media?parent=1707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}