Skip to content

Instantly share code, notes, and snippets.

@srijan
Last active February 10, 2024 04:17
Show Gist options
  • Save srijan/2028af568459195cb9a3dae8d111e754 to your computer and use it in GitHub Desktop.
Save srijan/2028af568459195cb9a3dae8d111e754 to your computer and use it in GitHub Desktop.
Install docker and docker-compose using ansible https://srijan.ch/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
cache_valid_time: 86400
- 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: Install docker-ce
apt:
name: docker-ce
state: present
cache_valid_time: 86400
- name: Install docker compose
apt:
name: docker-compose-plugin
state: present
cache_valid_time: 86400
- name: Run and enable docker
service:
name: docker
state: started
enabled: true
- name: Install docker-compose v1
when:
- docker_compose_install_v1 is defined
- docker_compose_install_v1
block:
- name: Check current docker-compose version.
command: docker-compose --version
register: docker_compose_vsn
changed_when: false
failed_when: false
check_mode: no
- name: Set docker compose current version
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_v1 }}/docker-compose-Linux-x86_64"
dest: /usr/local/bin/docker-compose
mode: 'a+x'
force: yes
when: >
docker_compose_current_version == ""
or docker_compose_current_version is version(docker_compose_version_v1, '<')
---
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_install_v1: true
docker_compose_version_v1: "1.29.2"
@srijan
Copy link
Author

srijan commented Nov 21, 2023

@chamalis - Updated, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment