{"id":598,"date":"2025-04-12T08:55:35","date_gmt":"2025-04-12T06:55:35","guid":{"rendered":"https:\/\/www.daminus.fr\/wordpress\/?p=598"},"modified":"2025-04-12T08:56:39","modified_gmt":"2025-04-12T06:56:39","slug":"le-duo-gagnant-dansible-et-terraform","status":"publish","type":"post","link":"https:\/\/www.daminus.fr\/wordpress\/?p=598","title":{"rendered":"Le Duo Gagnant d&rsquo;Ansible et Terraform"},"content":{"rendered":"\n<p>Dans le monde moderne de l&rsquo;infrastructure et du d\u00e9ploiement, <strong>l&rsquo;automatisation est la cl\u00e9<\/strong> pour garantir <strong>efficacit\u00e9, rapidit\u00e9 et scalabilit\u00e9<\/strong>. Deux outils phares \u00e9mergent pour transformer la gestion de nos syst\u00e8mes : <strong>Ansible<\/strong>, parfait pour la configuration et l\u2019administration, et <strong>Terraform<\/strong>, id\u00e9al pour le provisionnement d\u2019infrastructure.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-vivid-purple-color has-text-color has-link-color wp-elements-6dedc061b573d6448e446cf777d9d38d\">Partie 1 : Installer Ansible sur une machine Debian<\/h3>\n\n\n\n<p><strong>Pr\u00e9-requis :<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Une VM Debian (10, 11 ou 12) avec acc\u00e8s internet<\/li>\n\n\n\n<li>Les droits <code>sudo<\/code><\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\ud83d\udd27 \u00c9tapes :<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">bashCopierModifier<code>sudo apt update\nsudo apt install -y ansible\n<\/code><\/pre>\n\n\n\n<p><strong>V\u00e9rifier l\u2019installation :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bashCopierModifier<code>ansible --version\n<\/code><\/pre>\n\n\n\n<p><strong>Tips :<\/strong> Si tu veux g\u00e9rer des h\u00f4tes, configure ton fichier d\u2019inventaire :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">iniCopierModifier<code># \/etc\/ansible\/hosts\n[web]\n192.168.10.20 ansible_user=root\n<\/code><\/pre>\n\n\n\n<p>Tester la connexion :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bashCopierModifier<code>ansible web -m ping\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading has-vivid-purple-color has-text-color has-link-color wp-elements-56d2dc245880d68c4ed16005bdd1222f\">Partie 2 : Installer Terraform sur une autre Debian<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Pr\u00e9-requis :<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Deuxi\u00e8me VM Debian<\/li>\n\n\n\n<li>Acc\u00e8s root ou sudo<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u00c9tapes d\u2019installation :<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">bashCopierModifier<code>sudo apt update\nsudo apt install -y gnupg software-properties-common curl\n\ncurl -fsSL https:\/\/apt.releases.hashicorp.com\/gpg | sudo gpg --dearmor -o \/etc\/apt\/trusted.gpg.d\/hashicorp.gpg\n\necho \"deb [arch=amd64] https:\/\/apt.releases.hashicorp.com $(lsb_release -cs) main\" | \\\n  sudo tee \/etc\/apt\/sources.list.d\/hashicorp.list\n\nsudo apt update\nsudo apt install terraform\n<\/code><\/pre>\n\n\n\n<p>V\u00e9rifier :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bashCopierModifier<code>terraform -version\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading has-vivid-purple-color has-text-color has-link-color wp-elements-106013ac6bf0fd45f3eb44046fa24044\">Partie 3 : Cr\u00e9er des VMs VMware avec Terraform et un template Debian<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Pr\u00e9requis :<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Un vCenter op\u00e9rationnel (ou ESXi avec vSphere)<\/li>\n\n\n\n<li>Un <strong>template Debian<\/strong> pr\u00eat (par ex : <code>Debian12-Template<\/code>)<\/li>\n\n\n\n<li>Un compte utilisateur avec droits sur vSphere\/vCenter<\/li>\n\n\n\n<li>Un fichier <code>terraform.tf<\/code> sur la machine avec Terraform install\u00e9<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u00c9tapes :<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>T\u00e9l\u00e9charger le provider VMware :<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">bashCopierModifier<code>terraform init\n<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Exemple de configuration Terraform :<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">hclCopierModifier<code>provider \"vsphere\" {\n  user           = \"administrator@vsphere.local\"\n  password       = \"votre_mot_de_passe\"\n  vsphere_server = \"192.168.10.10\"\n\n  allow_unverified_ssl = true\n}\n\ndata \"vsphere_datacenter\" \"dc\" {\n  name = \"Datacenter\"\n}\n\ndata \"vsphere_datastore\" \"datastore\" {\n  name          = \"datastore1\"\n  datacenter_id = data.vsphere_datacenter.dc.id\n}\n\ndata \"vsphere_compute_cluster\" \"cluster\" {\n  name          = \"Cluster-1\"\n  datacenter_id = data.vsphere_datacenter.dc.id\n}\n\ndata \"vsphere_network\" \"network\" {\n  name          = \"VM Network\"\n  datacenter_id = data.vsphere_datacenter.dc.id\n}\n\ndata \"vsphere_virtual_machine\" \"template\" {\n  name          = \"Debian12-Template\"\n  datacenter_id = data.vsphere_datacenter.dc.id\n}\n\nresource \"vsphere_virtual_machine\" \"vm\" {\n  name             = \"Debian-Auto-01\"\n  resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id\n  datastore_id     = data.vsphere_datastore.datastore.id\n\n  num_cpus = 2\n  memory   = 2048\n  guest_id = data.vsphere_virtual_machine.template.guest_id\n\n  scsi_type = data.vsphere_virtual_machine.template.scsi_type\n\n  network_interface {\n    network_id   = data.vsphere_network.network.id\n    adapter_type = data.vsphere_virtual_machine.template.network_interface_types[0]\n  }\n\n  disk {\n    label            = \"disk0\"\n    size             = data.vsphere_virtual_machine.template.disks.0.size\n    eagerly_scrub    = false\n    thin_provisioned = true\n  }\n\n  clone {\n    template_uuid = data.vsphere_virtual_machine.template.id\n\n    customize {\n      linux_options {\n        host_name = \"debian-auto-01\"\n        domain    = \"local\"\n      }\n\n      network_interface {\n        ipv4_address = \"192.168.10.100\"\n        ipv4_netmask = 24\n      }\n\n      ipv4_gateway = \"192.168.10.1\"\n    }\n  }\n}\n<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Lancer la cr\u00e9ation de la VM :<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">bashCopierModifier<code>terraform init\nterraform plan\nterraform apply\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">R\u00e9sultat :<\/h3>\n\n\n\n<p>Une VM Debian est automatiquement d\u00e9ploy\u00e9e sur ton infra VMware \u00e0 partir d\u2019un template, avec une IP et un nom personnalis\u00e9.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dans cet article, nous allons explorer comment combiner ces deux technologies pour cr\u00e9er un workflow fluide et performant, simplifiant la gestion d\u2019infrastructure tout en r\u00e9duisant les erreurs et les interventions manuelles.<\/p>\n","protected":false},"author":1,"featured_media":602,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-598","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.daminus.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.daminus.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.daminus.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.daminus.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.daminus.fr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=598"}],"version-history":[{"count":1,"href":"https:\/\/www.daminus.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/598\/revisions"}],"predecessor-version":[{"id":601,"href":"https:\/\/www.daminus.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/598\/revisions\/601"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.daminus.fr\/wordpress\/index.php?rest_route=\/wp\/v2\/media\/602"}],"wp:attachment":[{"href":"https:\/\/www.daminus.fr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.daminus.fr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.daminus.fr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}