Install docker on multiple Ubuntu Xenial hosts with Ansible

Ansible is an amazing piece of configuration management software. Among its amazing features is that it’s totally agentless and the only 2 packages that it needs on any host are python and an SSH server.

Today we will create a playbook that will do the following:

  1. Add the stable docker repository to the software sources
  2. Add the gpg key
  3. install docker-ce package

It’s assumed that you have already added all required hosts to /etc/ansible/hosts and I’m naming this group “swarm”

- hosts: hostname
  remote_user: domain\user
  gather_facts: no

tasks:
 - name: add docker repo
   apt_repository:
     repo="deb https://download.docker.com/linux/ubuntu xenial stable"
     state=present
 - name: install repo gpg key
   apt_key:
     url="https://download.docker.com/linux/ubuntu/gpg"
     state=present
 - name: refresh cache and install docker-ce
   apt:
     name=docker-ce
     update_cache=yes
     state=latest

Enjoy!

Sources: Ansible Documentation

About SoCRaT

Systems Engineer, OSS & Linux Geek
This entry was posted in Ansible, Linux, Uncategorized and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s