Notes


Rôles Ansible

Rôle qui installe docker-engine et docker-compose

---
- name: "Install Docker Engine"
  tags: [docker-engine]
  hosts: localhost
  vars:
    docker_apt_release_channel: stable # stable edge
    docker_users: [userlab]
  tasks:
    - name: "ensure old versions of Docker are not installed"
      package:
        name: '{{ item }}'
        state: absent
      loop:
        - docker
        - docker-engine
    - name: "ensure dependencies are installed"
      apt:
        name:
          - apt-transport-https
          - ca-certificates
        state: present
      when: ansible_distribution == 'Ubuntu'
    - name: "add Docker apt key"
      apt_key:
        url: https://download.docker.com/linux/ubuntu/gpg
        id: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
        state: present
      ignore_errors: True
      when: ansible_distribution == 'Ubuntu'
    - name: "add Docker repository"
      apt_repository:
        repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic {{ docker_apt_release_channel }}"
        state: present
        update_cache: yes
      when: ansible_distribution == 'Ubuntu'
    - name: "install Docker"
      package:
        name: "docker-ce"
        state: present
    - name: "ensure docker users are added to the docker group"
      user:
        name: "{{ item }}"
        groups: docker
        append: yes
      loop: "{{ docker_users }}"
    - name: "ensure Docker is started and enabled at boot"
      service:
        name: docker
        state: started
        enabled: yes
  handlers:
    - name: docker_restart
      become: true
      service:
        name: docker
        state: restarted
- name: "Install Docker Compose"
  tags: [docker-compose]
  hosts: localhost
  vars:
    docker_compose_bin: /usr/local/bin/docker-compose
    docker_compose_version: latest
    docker_compose_as_root: yes
  tasks:
    - name: check latest docker version
      set_fact:
        docker_compose_latest_version: "{{ lookup('url', 'https://github.com/docker/compose/releases/latest') | regex_findall('download/([0-9]+[.][0-9]+[.][0-9]+)') | first }}"
      when: docker_compose_version == 'latest'
      changed_when: false
    - name: check installed docker compose version
      shell: "{{ docker_compose_bin }} --version | awk -F'[ ,]' '{ print $3; }' | grep {{ docker_compose_latest_version | default(docker_compose_version) }}"
      register: docker_compose_version_installed_result
      failed_when: false
      changed_when: false
    - name: store installed docker compose version result
      set_fact:
        docker_compose_desired_version_installed: "{{ docker_compose_version_installed_result.rc == 0 }}"
    - name: install docker-compose
      become: '{{ docker_compose_as_root }}'
      get_url:
        url: 'https://github.com/docker/compose/releases/download/{{ docker_compose_latest_version | default(docker_compose_version) }}/docker-compose-{{ ansible_system }}-{{ ansible_architecture }}'
        dest: '{{ docker_compose_bin }}'
        force: true
        mode: '555'
      when: docker_compose_desired_version_installed == false

Dockerfile et docker-compose.yml

Services

Blogs