Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install docker and docker-compose using ansible
---
- name: Install packages using apt
apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg2
- software-properties-common
state: present
update_cache: no
- name: Add Docker GPG apt Key
apt_key:
url: "{{ docker_apt_gpg_key }}"
state: present
- name: Add Docker Repository
apt_repository:
repo: "{{ docker_apt_repository }}"
state: present
update_cache: true
- name: Update apt and install docker-ce
apt: update_cache=no name=docker-ce state=present
- name: Check current docker-compose version.
command: docker-compose --version
register: docker_compose_vsn
changed_when: false
failed_when: false
check_mode: no
- set_fact:
docker_compose_current_version: "{{ docker_compose_vsn.stdout | regex_search('(\\d+(\\.\\d+)+)') }}"
when:
- docker_compose_vsn.stdout is defined
- name: Install or upgrade docker-compose
get_url:
url : "https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64"
dest: /usr/local/bin/docker-compose
mode: 'a+x'
force: yes
when: >
docker_compose_current_version is not defined
or docker_compose_current_version is version(docker_compose_version, '<')
- name: Run and enable docker
service:
name: docker
state: started
enabled: true
---
docker_apt_release_channel: stable
docker_apt_arch: amd64
docker_apt_repository: "deb [arch={{ docker_apt_arch }}] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} {{ docker_apt_release_channel }}"
docker_apt_gpg_key: https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg
docker_compose_version: "1.24.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.