# 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` - `apt_lock_files`: A list of apt lock files to check. - `arch`: The architecture of the host. - Default: `arm64` if `ansible_architecture` is `aarch64`, otherwise `amd64`. ### Docker - `docker.url`: The URL for the Docker repository. - Default: `https://download.docker.com/linux` - `docker.apt_release_channel`: The Docker apt release channel. - Default: `stable` - `docker.directories.local`: The local directory for Docker data. - Default: `/opt/local` - `docker.directories.config`: The directory for Docker configurations. - Default: `/opt/config` - `docker.directories.compose`: The directory for Docker Compose files. - Default: `/opt/compose` ### Keycloak - `keycloak_config`: A dictionary containing the Keycloak configuration. See `templates/keycloak/realm.json.j2` for more details. ### Services - `services`: A list of dictionaries, where each dictionary represents a Docker Compose service. See `templates/compose.yaml.j2` for more details. ## Tasks The role performs the following tasks: 1. **Setup VM**: - Includes `non-free` and `non-free-firmware` components in the apt sources. - Installs common packages. - Removes cloud kernel packages. - Reboots the host. 2. **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. 3. **Setup user and group for Docker**: - Ensures the `docker` group exists. - Adds the `ansible_user_id` to the `docker` group. - Reboots the host. 4. **Setup directory structure for Docker**: - Creates necessary directories for Docker and media. - Sets ownership of the directories. - Mounts NFS shares. 5. **Deploy configs**: - Sets up Keycloak realms if the host is a Keycloak host. 6. **Deploy Docker Compose**: - Copies the Docker Compose file to the target host. 7. **Publish metrics**: - Copies the `daemon.json` file to `/etc/docker/daemon.json` to enable metrics. ## 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. ```yaml - hosts: docker_hosts roles: - role: docker_host vars: # Your variables here ``` ## License This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.