Last active
November 15, 2024 03:30
-
-
Save rbq/886587980894e98b23d0eee2a1d84933 to your computer and use it in GitHub Desktop.
Install Docker CE on Ubuntu using Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: all | |
tasks: | |
- name: Install prerequisites for Docker repository | |
apt: | |
name: ['apt-transport-https', 'ca-certificates', 'curl', 'gnupg2', 'software-properties-common'] | |
update_cache: yes | |
- name: Add Docker GPG key | |
apt_key: | |
url: https://download.docker.com/linux/ubuntu/gpg | |
- name: Add Docker APT repository | |
apt_repository: | |
repo: deb [arch=amd64] https://download.docker.com/{{ ansible_system | lower }}/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable | |
- name: Install Docker CE | |
apt: | |
name: ['docker-ce', 'docker-ce-cli', 'containerd.io'] | |
update_cache: yes | |
- name: Install prerequisites for docker-compose | |
apt: | |
name: ['python3-pip', 'python3-setuptools', 'virtualenv'] | |
- name: Install docker-compose | |
pip: | |
name: docker-compose |
Docker on Ubuntu 22.04 AWS AMI from Canonical, sticking as close to the official install page as possible, and leaning on work from @yum-dev above:
- name: install prerequisites for Docker repository
become: yes
ansible.builtin.apt:
pkg:
- ca-certificates
- curl
- gnupg2
- lsb-release
- name: add docker apt key
become: yes
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: add docker apt repo
become: yes
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable"
state: present
update_cache: yes
- name: install docker and its dependencies
become: yes
apt:
pkg:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: present
- name: start and enable docker daemon
become: yes
service:
name: docker
state: started
enabled: yes
- name: start and enable containerd daemon
become: yes
service:
name: containerd
state: started
enabled: yes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mstevanic If you have
gather_facts: True
:)