bodsch.docker
Ansible Role: docker
This role sets up and installs dockerd.
This role has been moved to its own collection.
I will no longer accept or manage pull requests or issues here.Please use the new collection going forward!
Requirements & Dependencies
Ansible Collections
To install the collection, you can use:
ansible-galaxy collection install bodsch.core
or
ansible-galaxy collection install --requirements-file collections.yml
- Access to the docker-ce package repository
Operating Systems
Tested on:
- ArchLinux
- ArtixLinux
- Debian-based (e.g., Debian 10/11, Ubuntu 20.04/22.04)
RedHat-based systems are no longer officially supported! While they may work, it is not guaranteed.
Role Variables
You can adjust the following variables for your Docker setup:
## Docker repository channel settings
docker_repo:
channel:
stable_enabled: true
test_enabled: false
nightly_enabled: false
## Desired package state (present, absent, etc.)
docker_state: present
## Should the Docker daemon start when the system boots?
docker_service:
enable: true
## The name of the Docker service
name: docker
## Install a specific version of docker-compose
docker_compose: {}
# Example:
# docker_compose:
# install: true
# version: 1.29.2
docker_users: []
docker_plugins: []
docker_client_config: []
docker_config: {}
docker_config_diff: true
docker_python_packages: []
Proxy Configuration
Should the Docker daemon use a proxy for outgoing connections?
docker_proxy:
enabled: false
## List of environment variables to set (comment out any you don't need)
env:
- "HTTP_PROXY=http://proxy.example.com:80/"
- "HTTP_PROXY=https://proxy.example.com:443/"
- "NO_PROXY=localhost,127.0.0.1,internalhub.example.com"
Docker Client Configuration
Enable authentication for the Docker Registry.
You can create configurations for different users.
The password is stored as base64 and NOT encrypted!
You can create the security string like this:
echo "username:password" | base64
docker_client_config:
## Where to store client configuration
- location: "/root/.docker/config.json"
enabled: false
auths:
registry.gitfoo.tld:
auth: base64_encoded_string_here
Alternatively, you can directly enter your username
and password
.
The Ansible module will convert it into a valid Base64 string.
docker_client_config:
- location: "/var/tmp/foo/config.json"
enabled: false
auths:
"test.tld":
username: "username"
password: "password"
You can also configure the output format of docker ps
or docker images
starting from version 3.1.0.
Just define the parameters as a list:
docker_client_config:
- location: "/root/.docker/config.json"
enabled: false
auths:
registry.gitfoo.tld:
auth: base64_encoded_string_here
formats:
ps:
- ".ID"
- ".Names"
- ".Status"
- ".Labels"
- ".RunningFor"
- ".Ports"
images:
- ".ID"
- ".Size"
- ".Repository"
- ".Tag"
- ".CreatedAt"
Default Daemon Configuration Options
Currently supported options include:
Option | Type | Default | Description |
---|---|---|---|
authorization_plugins |
list |
[] |
|
bip |
string |
- |
Specify network bridge IP |
bridge |
string |
- |
Attach containers to a network bridge |
data_root |
string |
/var/lib/docker |
Root directory for Docker state |
... (other options) ... |
Example Configurations
docker_config:
data_root: /opt/docker
bip: 172.16.77.77/24
log_driver: journald
experimental: true
hosts:
- unix:///var/run/docker.sock
- tcp://0.0.0.0:2376
dns_search:
- lab1.linuxctl.com
- lab2.linuxctl.com
log_opts:
"max-size": 10m
"max-file": "3"
labels: molecule
env: "os,customer"
User and Plugin Options
Add existing users to the docker
group and set their access rights:
docker_users:
- jenkins
For custom plugins, such as Loki
, you can add:
docker_plugins:
- alias: loki
source: grafana/loki-docker-driver
version: 2.7.0
state: present
Python Support
This role may require specific Python packages.
You can customize the needed Python extensions as follows:
docker_python_packages:
- name: docker
- name: requests
- name: urllib3
Example Playbooks
Install Latest Docker Stable Release
- hosts: localhost
roles:
- role: docker
Install Latest Docker Edge Release
- hosts: localhost
vars:
docker_repo:
channel:
nightly_enabled: true
roles:
- role: docker
Advanced Playbook Example
- hosts: localhost
vars:
docker_config:
data_root: /opt/docker
bip: 172.16.77.77/24
log_driver: journald
experimental: true
hosts:
- unix:///var/run/docker.sock
- tcp://0.0.0.0:2376
dns_search:
- lab1.linuxctl.com
- lab2.linuxctl.com
log_opts:
"max-size": 10m
"max-file": "3"
labels: molecule
env: "os,customer"
roles:
- role: docker
Author and License
Original
docker
role by:- George Bolo | linuxctl.com
Modified by:
- Bodo Schulz
License
MIT
FREE SOFTWARE, HELL YEAH!
install and configure docker on various linux systems
ansible-galaxy install bodsch.docker