2.9 KiB
2.9 KiB
Ansible Role: Docker Host
This role sets up a Docker host, installs Docker, and configures it according to the provided variables. It also handles user and group management, directory setup, and deployment of Docker Compose services.
Role Variables
General
docker_host_package_common_dependencies: A list of common packages to be installed on the host.- Default:
nfs-common,firmware-misc-nonfree,linux-image-amd64
- Default:
apt_lock_files: A list of apt lock files to check.arch: The architecture of the host.- Default:
arm64ifansible_architectureisaarch64, otherwiseamd64.
- Default:
Docker
docker.url: The URL for the Docker repository.- Default:
https://download.docker.com/linux
- Default:
docker.apt_release_channel: The Docker apt release channel.- Default:
stable
- Default:
docker.directories.local: The local directory for Docker data.- Default:
/opt/local
- Default:
docker.directories.config: The directory for Docker configurations.- Default:
/opt/config
- Default:
docker.directories.compose: The directory for Docker Compose files.- Default:
/opt/compose
- Default:
Keycloak
keycloak_config: A dictionary containing the Keycloak configuration. Seetemplates/keycloak/realm.json.j2for more details.
Services
services: A list of dictionaries, where each dictionary represents a Docker Compose service. Seetemplates/compose.yaml.j2for more details.
Tasks
The role performs the following tasks:
- Setup VM:
- Includes
non-freeandnon-free-firmwarecomponents in the apt sources. - Installs common packages.
- Removes cloud kernel packages.
- Reboots the host.
- Includes
- Install Docker:
- Uninstalls old Docker versions.
- Installs dependencies for using repositories over HTTPS.
- Adds the Docker apt key and repository.
- Installs Docker Engine, containerd, and Docker Compose.
- Setup user and group for Docker:
- Ensures the
dockergroup exists. - Adds the
ansible_user_idto thedockergroup. - Reboots the host.
- Ensures the
- Setup directory structure for Docker:
- Creates necessary directories for Docker and media.
- Sets ownership of the directories.
- Mounts NFS shares.
- Deploy configs:
- Sets up Keycloak realms if the host is a Keycloak host.
- Deploy Docker Compose:
- Copies the Docker Compose file to the target host.
- Publish metrics:
- Copies the
daemon.jsonfile to/etc/docker/daemon.jsonto enable metrics.
- Copies the
Handlers
Restart docker: Restarts the Docker service.Restart compose: Restarts the Docker Compose services.Restart host: Reboots the host.
Usage
To use this role, include it in your playbook and set the required variables.
- hosts: docker_hosts
roles:
- role: docker_host
vars:
# Your variables here
License
This project is licensed under the MIT License - see the LICENSE.md file for details.