Giter Site home page Giter Site logo

ansible-role-docker's Introduction

Ansible Role: Docker

This role install and configures Docker as well as compose and Docker SDK for Python.

Requirements

This role developed and tested with following Ansible versions:

Name Version
ansible >= 2.9.13
ansible-base >= 2.10.1
ansible-core >= 2.11.2

Other Ansible versions was not tested but will probably work.

Installation

Use ansible-galaxy install igor_nikiforov.docker to install the latest stable release of role.

You could also install it from requirements ansible-galaxy install -r requirements.yml:

# requirements.yml
---
roles:
  - name: igor_nikiforov.docker
    version: v1.1.0

Platforms

Name Version
Debian buster
Ubuntu focal, groovy
CentOS 7.4+, 8
RedHat 7.4+, 8

Other OS distributions was not tested but will probably work. In case if not please raise a PR!

Variables

Name Description Default
docker_supported_architectures List of Docker supported architectures ["x86_64", "arm64", "armhf", "s390x"]
docker_install If True, Docker will be installed true
docker_version Docker version latest
docker_bash_completion_install If True, Docker bash completion will be installed true
docker_daemon_config Docker daemon configuration {}
docker_service_enabled Whether Docker service should start on boot true
docker_service_state State of Docker service started
docker_users List of users to be added to docker group []
docker_sdk_for_python_install If True, Docker SDK for Python will be installed false
docker_sdk_for_python_version Docker SDK for Python version latest
docker_compose_install If True, Docker Compose will be installed false
docker_compose_version Docker Compose version latest
docker_compose_bash_completion_install If True, Docker Compose bash completion will be installed true

Usage

Role supports all Docker daemon configuration parameters which could be passed via docker_daemon_config variable. You could find example of JSON config format in Docker official documentation. For usage in role you should convert config from JSON to YAML format, for example using this online tool.

Examples

# playbook.yml
---
- hosts: all
  become: True
  gather_facts: False

  pre_tasks:
    - wait_for_connection: { timeout: 300 }
    - setup:

  vars:
    docker_sdk_for_python_install: True
    docker_compose_install: True
    docker_daemon_config:
      default-address-pools:
        - { base: 172.16.0.0/16, size: 26 }
      log-driver: "json-file"
      log-opts:
        max-size: "10m"
        max-file: "3"

  tasks:
    - name: Install Docker
      import_role:
        name: docker

License

MIT

Author Information

Igor Nikiforov

ansible-role-docker's People

Contributors

edrex avatar igor-nikiforov avatar jidckii avatar voje avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ansible-role-docker's Issues

Handling faulty docker.daemon settings

Currently, the playbook tries to start/enable the dockerd service (or whatever we specify in the config) and then it tries to apply new docker.daemon settings (and restart the daemon again).

The problem is when we apply faulty docker.daemon settings, we can't reapply new ones because the playbook aborts before getting to the configure-docker-daemon tasks.

Suggested fix: configure docker daemon before starting/enabling it.

Installing of bash completion on Debian Buster failed when docker_version is set

Given this minimal Ansible play running against Debian Buster

- hosts: test
  become: yes
  roles:
    - igor_nikiforov.docker
  vars:
    docker_version: 5:20.10.11~3-0~debian-buster

The Ansible run fails for the task installing the bash completion

TASK [igor_nikiforov.docker : Install Docker bash completion.] *****************
fatal: [test]: FAILED! => {"changed": false, "dest": "/etc/bash_completion.d/docker", "elapsed": 0, "msg": "Request failed", "response": "HTTP Error 404: Not Found", "status_code": 404, "url": "https://raw.githubusercontent.com/docker/cli/v5:20.10.11~3-0~debian-buster/contrib/completion/bash/docker"}

Looks like version strings on Debian and on the Github Docker CLI repository are no longer compatible.

Failed: Install Docker Compose bash completion (Error 404: Not Found)

@jidckii Hi!

There is an error while installing Docker Compose bash completion.

TASK [igor_nikiforov.docker : Install Docker Compose bash completion.] ***********************************************************************************************************
fatal: [alfa]: FAILED! => {"changed": false, "dest": "/etc/bash_completion.d/docker-compose", "elapsed": 0, "msg": "Request failed", "response": "HTTP Error 404: Not Found", "status_code": 404, "url": "https://raw.githubusercontent.com/docker/cli/master/contrib/completion/bash/docker-compose"}

My host:

root@vm1272769:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.3 LTS
Release:	20.04
Codename:	focal
root@vm1272769:~# docker-compose version
docker-compose version 1.29.2, build unknown
docker-py version: 5.0.3
CPython version: 3.8.10
OpenSSL version: OpenSSL 1.1.1f  31 Mar 2020

Failed to install docker on Centos 7.8

Got error msg as below:

MSG:

The conditional check 'ansible_distribution_major_version < 8' failed. The error was: Unexpected templating type error occurred on ({% if ansible_distribution_major_version < 8 %} True {% else %} False {% endif %}): '<' not supported between instances of 'AnsibleUnsafeText' and 'int'

The error appears to be in '/Users/ichen/.ansible/roles/igor_nikiforov.docker/tasks/install-docker-RHEL.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- name: Ensure old versions of Docker are not installed.
  ^ here

The facts from ansible <hostname> -m ansible.builtin.setup are:

        "ansible_distribution": "CentOS",
        "ansible_distribution_file_parsed": true,
        "ansible_distribution_file_path": "/etc/redhat-release",
        "ansible_distribution_file_variety": "RedHat",
        "ansible_distribution_major_version": "7",
        "ansible_distribution_release": "Core",
        "ansible_distribution_version": "7.8",

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.