The Docker role

As with all of the roles we have created so far, we are going to use the ansible-galaxy command to generate the structure for our role:

$ ansible-galaxy init roles/docker

For our Docker installation, we will be using the yum repository provided by Docker itself; this means that before we install, Docker needs to enable the repository. Once enabled, we will be able to install the latest stable release. Let's make a start by populating some defaults in roles/docker/defaults/main.yml:

docker:  gpg_key: "https://download.docker.com/linux/centos/gpg"  repo_url: "https://download.docker.com/linux/centos/docker-ce.repo"  repo_path: "/etc/yum.repos.d/docker-ce.repo"  packages:    - "docker-ce"    - "device-mapper-persistent-data"    - "lvm2"

Get Learn Ansible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.