Skip to content

Instantly share code, notes, and snippets.

@jjromannet
Last active February 5, 2022 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjromannet/b0bc867fce6ce9ad09aa57c7e7525bc6 to your computer and use it in GitHub Desktop.
Save jjromannet/b0bc867fce6ce9ad09aa57c7e7525bc6 to your computer and use it in GitHub Desktop.
Ansible playbook to install docker with apt, and docker compose
# based on:
#. doceker install: https://docs.docker.com/engine/install/debian/#install-using-the-repository
#. compose install: https://github.com/docker/compose#where-to-get-docker-compose
#
# usage: ansible-playbook -i hosts-file docker/docker-install.yaml
#
# contents of hosts-file:
# [docker]
# 192.168.0.101
---
- hosts: docker
tasks:
# accommodate of suite rename in debian buster from stable to oldstable
- name: Allow Release Info change
lineinfile:
path: /etc/apt/apt.conf.d/99releaseinfochange
state: present
create: yes
line: Acquire::AllowReleaseInfoChange::Suite "true";
- name: Update apt cache - valid time so it is not marked by ansible by each execution
apt:
update_cache: yes
cache_valid_time: 86400
- name: install utils
apt:
name:
- ca-certificates
- curl
- gnupg
- lsb-release
- name: add apt key for docker repo
apt_key:
keyring: /etc/apt/trusted.gpg.d/docker-archive-keyring.gpg
url: https://download.docker.com/linux/debian/gpg
- name: Add specified repository into sources list
ansible.builtin.apt_repository:
repo: deb https://download.docker.com/linux/debian buster stable
state: present
- name: Update apt cache - valid time so it is not marked by ansible by each execution
apt:
update_cache: yes
cache_valid_time: 86400
- name: install docker
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
## installing docker compose
- name: get name of OS
command: "uname -s"
register: osname
changed_when: False
- name: get arch of OS
command: "uname -m"
register: archname
changed_when: False
- name: Download compose cli plugin
get_url:
url: https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-{{ osname.stdout }}-{{ archname.stdout }}
dest: /usr/libexec/docker/cli-plugins/docker-compose
mode: 'a+rx,g-w,o-w'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment