initial checkin

This commit is contained in:
Radar231 2021-07-22 23:14:55 -04:00
commit 1be8a79c5d
2 changed files with 162 additions and 0 deletions

15
README.md Normal file
View File

@ -0,0 +1,15 @@
# Ansible Role: docker
## Introduction
This role will install docker on the target host.
This role should work on both Ubuntu and CentOS based hosts.
NOTE:
The following variables must be specified in the calling playbook (usually
done by doing a 'gather_facts' action);
{{ ansible_distribution }}

147
tasks/main.yml Normal file
View File

@ -0,0 +1,147 @@
---
###########################################################################
#
# This playbook is based on the steps presented at;
# - https://docs.docker.com/engine/install/ubuntu/
# - https://docs.docker.com/engine/install/centos/
#
###########################################################################
# tasks file for main.yml
############################################################
- name: Ensure old docker packages are removed (Ubuntu)
apt:
name:
- docker
- docker-engine
- docker.io
- containerd
- runc
state: absent
when: ansible_distribution == "Ubuntu" or ansible_distribution == "Pop!_OS"
############################################################
- name: Ensure old docker packages are removed (CentOS)
yum:
name:
- docker-client
- docker-client-latest
- docker-common
- docker-latest
- docker-latest-logrotate
- docker-logrotate
- docker-engine
- podman
- runc
- buildah
state: absent
when: ansible_distribution == "CentOS"
############################################################
- name: Ensure required supporting packages are installed (Ubuntu)
apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
state: present
when: ansible_distribution == "Ubuntu" or ansible_distribution == "Pop!_OS"
############################################################
- name: Ensure required supporting packages are installed (CentOS)
yum:
name:
- yum-utils
state: present
when: ansible_distribution == "CentOS"
############################################################
- name: Retrieve docker's official GPG key (Ubuntu)
shell:
cmd: >
/usr/bin/curl -fsSL
https://download.docker.com/linux/ubuntu/gpg
| /usr/bin/apt-key add -
when: ansible_distribution == "Ubuntu" or ansible_distribution == "Pop!_OS"
############################################################
- name: Add the stable docker repository (Ubuntu)
shell:
cmd: >
/usr/bin/add-apt-repository
"deb https://download.docker.com/linux/ubuntu
{{ ansible_distribution_release }}
stable"
when: ansible_distribution == "Ubuntu" or ansible_distribution == "Pop!_OS"
############################################################
- name: Add the stable docker repository (CentOS)
shell:
cmd: >
/usr/bin/yum-config-manager
--add-repo
https://download.docker.com/linux/centos/docker-ce.repo
when: ansible_distribution == "CentOS"
############################################################
- name: Update package cache (Ubuntu)
apt:
update-cache: true
when: ansible_distribution == "Ubuntu" or ansible_distribution == "Pop!_OS"
############################################################
- name: Install docker packages (Ubuntu)
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
state: present
when: ansible_distribution == "Ubuntu" or ansible_distribution == "Pop!_OS"
############################################################
- name: Install docker packages (CentOS)
yum:
name:
- docker-ce
- docker-ce-cli
- containerd.io
state: present
when: ansible_distribution == "CentOS"
############################################################
- name: Add user to docker group
user:
name: "{{ username }}"
groups: docker
append: true
############################################################
- name: Enable docker daemon
systemd:
name: docker
enabled: true
############################################################
# using the pip3 command rather than the pip ansible module
# because ansible can get in a weird state depending on the
# python version used on the target host (python 2 on CentOS 7
# vs python 3 otherwise)
- name: Install docker python package
shell:
cmd: pip3 install docker
############################################################
- name: Install docker-compose
shell:
cmd: curl -L "https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
############################################################
- name: Set permissions on /usr/local/bin/docker-compose
file:
path: /usr/local/bin/docker-compose
mode: "0755"
# EOF