In your efforts to run hosts for Docker containers, you will inevitably come across the need to install Docker automatically via configuration management.

Here is a quick Ansible playbook to install Docker on Ubuntu 18.04 Bionic, and optionally, enable Docker to use insecure registries in a defined IP address or range:

- hosts: all
  become: true

    - name: ensure repository key is installed
        state: present

    - name: ensure docker registry is available
      apt_repository: repo='deb bionic stable' state=present

    - name: ensure docker and dependencies are installed
      apt: name=docker-ce update_cache=yes

    # Uncomment the following to enable insecure registries with Docker
    #- name: ensure docker can use insecure registries in
    #  lineinfile: "dest=/etc/default/docker regexp=^DOCKER_OPTS line=DOCKER_OPTS='--insecure-registry'"

    - service: name=docker state=restarted

Please note, though, that using insecure registries is made difficult on purpose. You should opt for using a secured registry whenever possible.

Releaseworks Academy has a free online training course on Docker & Jenkins best practices: