Installing Docker Engine in Fedora 25 via Ansible

Docker is an open source container platform. The container encapsulating everything it needs including libraries, code, system tools, runtime etc.

From Docker site

Docker containers wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries – anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.

I have tried the script in Fedora 25. But it should work fine in Fedora 24 also.

For the manual steps refer https://docs.docker.com/engine/installation/linux/fedora/

Ansible script for Docker Engine

- hosts: docker_server
  become: true
  tasks:
  - name: install python modules.
    dnf:
      name: python2
      state: present

  - name: Install python-dnf module
    dnf:
      name: python-dnf
      state: present

  - name: Remove existing unofficial Docker packages
    dnf:
      name: "{{ item }}"
      state: absent
    with_items:
      - docker
      - docker-common
      - container-selinux
      - docker-selinux

  - name: Install dnf-plugins-core to manage DNF repository
    dnf:
      name:  dnf-plugins-core
      state: present

  - name: Add docker repo
    shell:  'dnf config-manager \
      --add-repo \
      https://docs.docker.com/engine/installation/linux/repo_files/fedora/docker.repo'

  - name: Update dnf package index
    dnf:
     name: docker-engine
     state: latest

  - name: Start docker service
    systemd:
      state: started
      name: docker

To verify the docker installation was successful run the following command after the script is run.

sudo docker run hello-world