Ansible Playbook for Installing Docker on Linux Systems
By Luca Berton · Published 2024-01-01 · Category: installation
Learn how to install Docker on Linux systems using an Ansible playbook. Follow our guide for a seamless Docker setup and start process.
How to Install Docker in RedHat-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 RedHat-like systems • Add Docker key => ansible.builtin.rpm_key • Add Docker repository => ansible.builtin.yum_repository • Update yum cache and install Docker => ansible.builtin.yum
In order to install Docker on a RedHat-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.rpm_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 where yum/DNF, your distribution package manager looks like for software. You are going to use the ansible.builtin.yum_repository Ansible module. The third step is to update the yum cache for the available packages and install Docker using the ansible.builtin.yum Ansible module.
Parameters • rpm_key key string - URL • rpm_key state string - present/absent • yum_repository name string - repository • yum_repository baseurl string - URL • yum_repository gpgcheck boolean gpgkey string - GPG check and key URL • yum name string - name or package specific • yum state string - latest/present/absent • yum update_cache boolean - no/yes
For the ansible.builtin.rpm_key Ansible module I'm going to use two parameters: "key" and "state". The "key" parameter specifies the URL or the key ID of the repository GPG signature key and the "state" verify that is present in our system after the execution. For the ansible.builtin.yum_repository Ansible module I'm going to use four parameters: "name", "baseurl", "gpgcheck" and "gpgkey". The "name" parameter specifies the repository parameters and the "baseurl" URL of it. The "gpgcheck" parameter enables the GPG verification with the URL specified in "gpgkey" parameter. For the ansible.builtin.yum 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 yum cache to ensure that the latest version of the package is going to be downloaded.
Links • https://docs.docker.com/engine/install/ • https://github.com/docker/docker.github.io/issues/13463
## Playbook
Install Docker in RedHat-like systems with Ansible Playbook.
code
execution
idempotency
before execution
after execution
Conclusion
Now you know how to install Docker in RedHat-like systems with Ansible.
Related Articles • Ansible Docker Guide • Ansible Inventory Guide • Ansible set_fact Guide • Ansible Become Guide
Category: installation
Watch the video: Ansible Playbook for Installing Docker on Linux Systems — Video Tutorial