From 0161c78d3d7aa39129cb45ea969d75f236609666 Mon Sep 17 00:00:00 2001 From: Bateast Date: Fri, 1 Nov 2024 21:32:14 +0000 Subject: [PATCH] Ajouter Ansible/docker_install.yml --- Ansible/docker_install.yml | 83 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Ansible/docker_install.yml diff --git a/Ansible/docker_install.yml b/Ansible/docker_install.yml new file mode 100644 index 0000000..6ddf60d --- /dev/null +++ b/Ansible/docker_install.yml @@ -0,0 +1,83 @@ +--- +- name: Installation de Docker, Docker Compose et Docker Swarm + hosts: all + become: true + vars: + docker_version: "20.10" + docker_compose_version: "1.29.2" + + tasks: + - name: Mise à jour du cache APT + apt: + update_cache: yes + + - name: Installation des paquets requis + apt: + name: + - apt-transport-https + - ca-certificates + - curl + - software-properties-common + state: present + + - name: Ajout de la clé GPG officielle de Docker + apt_key: + url: https://download.docker.com/linux/ubuntu/gpg + state: present + + - name: Ajout du dépôt Docker APT + apt_repository: + repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable" + state: present + + - name: Mise à jour du cache APT après ajout du dépôt Docker + apt: + update_cache: yes + + - name: Installation de Docker CE + apt: + name: "docker-ce={{ docker_version }}*" + state: present + + - name: Vérification de l'installation de Docker + command: docker --version + register: docker_version_result + + - name: Afficher la version de Docker installée + debug: + msg: "Docker version installed: {{ docker_version_result.stdout }}" + + - name: Ajout de l'utilisateur courant au groupe docker + user: + name: "{{ ansible_user_id }}" + groups: docker + append: yes + + - name: Téléchargement de Docker Compose + get_url: + url: "https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-{{ ansible_system }}-{{ ansible_architecture }}" + dest: "/usr/local/bin/docker-compose" + mode: 'a+x' + + - name: Vérification de l'installation de Docker Compose + command: docker-compose --version + register: docker_compose_version_result + + - name: Afficher la version de Docker Compose installée + debug: + msg: "Docker Compose version installed: {{ docker_compose_version_result.stdout }}" + + - name: Initialisation de Docker Swarm (seulement si non initialisé) + command: docker swarm init + register: docker_swarm_result + failed_when: docker_swarm_result.rc != 0 and "This node is already part of a swarm" not in docker_swarm_result.stderr + ignore_errors: yes + + - name: Vérification de l'état de Docker Swarm + command: docker info + register: docker_info_result + failed_when: "'Swarm: active' not in docker_info_result.stdout" + + - name: Afficher l'état de Docker Swarm + debug: + msg: "Docker Swarm status: {{ docker_info_result.stdout_lines | select('search', 'Swarm') | list }}"