#!/usr/bin/env ansible-playbook
---
#==============================================================#
# File      :   docker.yml
# Desc      :   init docker on nodes
# Ctime     :   2023-02-20
# Mtime     :   2026-01-18
# Path      :   docker.yml
# Docs      :   https://pigsty.io/docs/docker/playbook
# License   :   Apache-2.0 @ https://pigsty.io/docs/about/license/
# Copyright :   2018-2026  Ruohang Feng / Vonng (rh@vonng.com)
#==============================================================#
- name: DOCKER INIT
  hosts: all
  gather_facts: no
  become: true
  vars:
    #docker_enabled: false             # enable docker on this node? false by default
    #docker_data: /data/docker         # docker data directory, /data/docker by default
    #docker_storage_driver: overlay2   # docker storage driver: overlay2,zfs,btrfs
    #docker_cgroups_driver: systemd    # docker cgroup fs driver: cgroupfs,systemd
    #docker_registry_mirrors: [ ]      # docker registry mirror list
    #docker_exporter_port: 9323        # docker metrics exporter port, 9323 by default
    #docker_image: []                  # docker image to be pulled after bootstrap
    #docker_image_cache: /tmp/docker/*.tgz # docker image cache file/glob, `/tmp/docker/*.tgz` by default
  roles:
    - { role: node_id , tags: id     }  # get node identity (always)
    - { role: docker  , tags: docker ,when: docker_enabled is defined and docker_enabled|bool }


#---------------------------------------------------------------
# Usage
#---------------------------------------------------------------

# Set parameter `docker_enabled: true` on target nodes, then:
#
# ./docker.yml -l <group|host>
#
# docker images on /tmp/docker/*.tgz will be loaded automatically
# you can add registry mirror to `docker_registry_mirrors` to accelerate
#
# one-time online installation
# ./node.yml -t node_install -e '{"node_repo_modules":"node,docker","node_packages":["docker-ce,docker-compose-plugin"]}'
#
# install docker with mirror
# ./docker.yml -e '{"docker_enabled":"true","docker_registry_mirrors":["https://docker.xxxxxx.io"]}'
#---------------------------------------------------------------
# Tasks
#---------------------------------------------------------------
# docker               : setup docker on node to run containers (optional)
#   - docker_install   : install docker on nodes
#   - docker_admin     : add user to docker admin group
#   - docker_dir       : create docker data directory
#   - docker_config    : generate docker daemon config
#   - docker_launch    : launch docker daemon systemd service
#   - docker_register  : register docker target to victoria metrics
#   - docker_image     : load docker images from /tmp/docker/*.tgz if exists
#---------------------------------------------------------------
...
