AnsiblePilot — Master Ansible Automation
AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.
Popular Topics
About Luca Berton
Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.
Install Docker in Debian-like systems - Ansible module apt_key, apt_repository and apt — Video Tutorial
How to automate the installation of the docker-ce engine in Ubuntu 20.04 LTS x86_64 (or amd64) using Ansible Playbook. The procedure is going to take care of the GPG signing key, add a repository into the sources list, and install the latest docker-ce package. Included Demo for Debian-like workstation (Debian and Ubuntu).
What You'll Learn
- How to Install Docker in Debian-like systems with Ansible?
- Ansible install Docker in Debian-like systems
- Parameters
- Links
- updated
- original code
- execution
- idempotency
- before execution
- after execution
Full Tutorial Content
How to Install Docker in Debian-like systems with Ansible?
I'm going to show you a live Playbook with some simple Ansible code.
I'm Luca Berton and welcome to today's episode of Ansible Pilot.
Ansible install Docker in Debian-like systems
- Add Docker key => `ansible.builtin.apt_key`
- Add Docker repository => `ansible.builtin.apt_repository`
- Update apt cache and install Docker => `ansible.builtin.apt`
In order to install Docker on a Debian-like system we need to perform three different steps.
The first step is to download the GPG signature key for the repository. You are going to use the `ansible.builtin.apt_key` Ansible module.
This encrypted key verifies the genuinity of the packages and the repository and guarantees that the software is the same as Docker releases.
The second step is to add the add Docker repository to the distribution. It's an extra website were `apt`, your distribution package manager looks like for software.
You are going to use the `ansible.builtin.apt_repository` Ansible module.
The third step is to update the apt cache for the available packages and install Docker (`docker-ce`) using the `ansible.builtin.apt` Ansible module.
Parameters
- `apt-key` `url` string - URL
- `apt-key` `state` string - present/absent
- `apt_repository` `repo` string - repository
- `apt_repository` `state` string - present/absent
- `apt` `name` string - name or package specific
- `apt` `state` string - latest/present/absent
- `apt` `update_cache` boolean - no/yes
For the `ansible.builtin.apt_key` Ansible module I'm going to use two parameters: "`url`" and "`state`".
The "url" parameter specifies the URL of the repository GPG signature key and the "state" verify that is present in our system after the execution.
For the `ansible.builtin.apt_repository` Ansible module I'm going to use two parameters: "`repo`" and "state".
The "`repo`" parameter specifies the repository parameters and the "`state`" verify that is present in our system after the execution.
For the `ansible.builtin.apt` Ansible module I'm going to use three parameters: "`name`", "`state`", and "`update_cache`".
The "`name`" parameter specifies the package name (Docker in our use-case) and the "`state`" verify that is present in our system after the execution.
Before installing the package the "`update_cache`" performs an update of the apt-cache to ensure that the latest version of the package is going to be downloaded.
Links
- [Install Docker Engine](https://docs.docker.com/engine/install/)
## Playbook
Install Docker in Debian-like systems with Ansible Playbook
updated
Package `docker-ce` changed name to `docker`.
```yaml
---
- name: install Docker
hosts: all
become: true
tasks:
- name: Install apt-transport-https
ansible.builtin.apt:
name:
- apt-transport-https
- ca-certificates
- lsb-release
- gnupg
state: latest
update_cache: true
- name: Add signing key
ansible.builtin.apt
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 6 min
- Category: installation
Read the full written article: Install Docker in Debian-like systems - Ansible module apt_key, apt_repository and apt
Related Video Tutorials
- Install Google Chrome in Debian like systems - Ansible module apt_key, apt_repository and apt — How to install the latest Google Chrome Stable on a Debian-like workstation (Debian, Ubuntu, Linux Mint, MX Linux, Deepin, AntiX, PureOS, Kali Linux, Parrot OS, Devuan, Knoppix, AV Linux Linux) verify software using the public GPG key and set up the Google repository. Included Playbook in Ubuntu 20.04 LTS.
- Install Microsoft Edge on Debian with Ansible — Learn how to install Microsoft Edge on Debian using Ansible. Follow our guide for a smooth setup process, including repository and key additions.
- Ansible Playbook for Installing Docker on Linux Systems — Learn how to install Docker on Linux systems using an Ansible playbook. Follow our guide for a seamless Docker setup and start process.
- Install Spotify snap in Debian-like systems - Ansible module snap — How to automate the installation of Spotify snap system-wide in Debian-like systems using Ansible module snap.
- Install Zoom flatpak in Debian-like systems - Ansible module flatpak — How to automate the installation of Zoom flatpak system-wide in Debian-like systems using Ansible module flatpak.
- Install Docker in Windows-like systems - Ansible module win_chocolatey — How to automate the installation of the latest version of Docker Desktop in your Windows-like system with Ansible Playbook and Chocolatey.