84 lines
2.7 KiB
YAML
84 lines
2.7 KiB
YAML
---
|
|
- 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 }}"
|