Skip to content

Commit

Permalink
Ubuntu 20 + CentOS 8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
marverix committed Apr 10, 2021
1 parent 31f827c commit 3c343f1
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 129 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Ansible role that installs on linux Docker CE + Docker Compose + Python Docker S
- ✔️ Ubuntu 18.04 (Bionic)
- ✔️ Ubuntu 20.04 (Focal)
- ✔️ CentOS 7
- ✔️ CentOS 8

## Requirements

Expand Down
1 change: 1 addition & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ galaxy_info:
- name: EL
versions:
- 7
- 8

galaxy_tags:
- docker
Expand Down
7 changes: 7 additions & 0 deletions molecule/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ platforms:
volumes:
- /var/run/docker.sock:/var/run/docker.sock:rw

- name: centos8
image: pycontribs/centos:8
pre_build_image: true
privileged: true
volumes:
- /var/run/docker.sock:/var/run/docker.sock:rw

provisioner:
name: ansible

Expand Down
7 changes: 7 additions & 0 deletions tasks/install-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Install Docker Compose
pip:
name: docker-compose
version: "{{ docker_compose_version }}"
state: present
executable: "{{ docker_os_dict.pip }}"
7 changes: 7 additions & 0 deletions tasks/install-docker-sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Install Docker SDK
pip:
name: docker
version: "{{ docker_sdk_version }}"
state: present
executable: "{{ docker_os_dict.pip }}"
109 changes: 109 additions & 0 deletions tasks/install-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---

# https://docs.docker.com/install/linux/docker-ce/ubuntu/
- name: Ubuntu support
when: ansible_distribution == 'Ubuntu'
block:

- name: Uninstall old packages
apt:
name:
- docker
- docker-engine
- docker.io
- containerd
- runc
state: absent

- name: Install dependencies
apt:
name:
- apt-transport-https
- ca-certificates
- gnupg-agent
- software-properties-common
state: present
update_cache: yes

- name: Add key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
id: "{{ docker_apt_gpg_key_id }}"
state: present

- name: Add repository
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
state: present

- name: Install Docker CE
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
state: present
update_cache: yes


# https://docs.docker.com/install/linux/docker-ce/centos/
- name: CentOS support
when: ansible_distribution == 'CentOS'
block:

- name: Uninstall old packages
yum:
name:
- docker
- docker-client
- docker-client-latest
- docker-common
- docker-latest
- docker-latest-logrotate
- docker-logrotate
- docker-engine
state: absent

- name: Install dependencies
yum:
name:
- yum-utils
- device-mapper-persistent-data
- lvm2
state: present
update_cache: yes

- name: Add repository
yum_repository:
name: docker-ce
description: Docker CE Stable
baseurl: "https://download.docker.com/linux/centos/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/stable"
enabled: yes
gpgkey: https://download.docker.com/linux/centos/gpg
gpgcheck: yes
state: present

- name: Install Docker CE
yum:
name:
- docker-ce
- docker-ce-cli
- containerd.io
state: present
update_cache: yes

- name: Enable Docker
service:
name: docker
state: started
enabled: yes
ignore_errors: yes

- name: Flush handlers
meta: flush_handlers

- name: Add user to docker group
user:
name: "{{ docker_user | default(ansible_user_id) }}"
groups: docker
append: yes
139 changes: 10 additions & 129 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,138 +1,19 @@
---
- name: "Update pip"
pip:
name: pip
version: "{{ pip_version }}"
extra_args: --upgrade
- name: Set facts
set_fact:
docker_os_dict: "{{ docker_os_dicts[ansible_distribution + '_' + ansible_distribution_major_version] }}"

# https://docs.docker.com/install/linux/docker-ce/ubuntu/
- name: Install Docker CE on Ubuntu
when: ansible_distribution == 'Ubuntu'
block:
- name: Install Docker CE
include_tasks: install-docker.yml

- name: Uninstall old packages
apt:
name:
- docker
- docker-engine
- docker.io
- containerd
- runc
state: absent

- name: Double-check dependencies
apt:
name:
- apt-transport-https
- ca-certificates
- gnupg-agent
- software-properties-common
# Below are for Docker Compose
- build-essential
- libssl-dev
- libffi-dev
- python-dev
state: present
update_cache: yes

- name: Add key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
id: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
state: present

- name: Add repository
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
state: present

- name: Install Docker CE
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
state: present
update_cache: yes


# https://docs.docker.com/install/linux/docker-ce/centos/
- name: Install Docker CE on CentOS
when: ansible_distribution == 'CentOS'
block:

- name: Uninstall old packages
yum:
name:
- docker
- docker-client
- docker-client-latest
- docker-common
- docker-latest
- docker-latest-logrotate
- docker-logrotate
- docker-engine
state: absent

- name: Double-check dependencies
yum:
name:
- yum-utils
- device-mapper-persistent-data
- lvm2
# Below are for Docker compose
- gcc
- libffi-devel
- python-devel
- openssl-devel
state: present
update_cache: yes

- name: Add repository
yum_repository:
name: docker-ce
description: Docker CE Stable
baseurl: "https://download.docker.com/linux/centos/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/stable"
enabled: yes
gpgkey: https://download.docker.com/linux/centos/gpg
gpgcheck: yes
state: present

- name: Install Docker CE
yum:
name:
- docker-ce
- docker-ce-cli
- containerd.io
state: present
update_cache: yes

- name: Enable Docker
service:
name: docker
state: started
enabled: yes
ignore_errors: yes

- name: Flush handlers
meta: flush_handlers
- name: Prepare Python
include_tasks: prepare-python.yml
when: docker_sdk_version != false or docker_compose_version != false

- name: Install Docker SDK
pip:
name: docker
version: "{{ docker_sdk_version }}"
state: present
include_tasks: install-docker-sdk.yml
when: docker_sdk_version != false

- name: Install Docker Compose
pip:
name: docker-compose
version: "{{ docker_compose_version }}"
state: present
include_tasks: install-docker-compose.yml
when: docker_compose_version != false

- name: Add user to docker group
user:
name: "{{ docker_user | default(ansible_user_id) }}"
groups: docker
append: yes
37 changes: 37 additions & 0 deletions tasks/prepare-python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---

- name: Ubuntu support
when: ansible_distribution == 'Ubuntu'
block:

- name: Install dependencies
apt:
name:
- build-essential
- libssl-dev
- libffi-dev
- "{{ docker_os_dict.python_dev }}"
state: present
update_cache: yes

- name: CentOS support
when: ansible_distribution == 'CentOS'
block:

- name: Install dependencies
yum:
name:
- gcc
- libffi-devel
- openssl-devel
- "{{ docker_os_dict.python_dev }}"
state: present
update_cache: yes


- name: Update pip
pip:
name: pip
version: "{{ pip_version }}"
extra_args: --upgrade
executable: "{{ docker_os_dict.pip }}"
20 changes: 20 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
docker_apt_gpg_key_id: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88

docker_os_dicts:
Ubuntu_16:
pip: pip
python_dev: python-dev
Ubuntu_18:
pip: pip
python_dev: python-dev
Ubuntu_20:
pip: pip3
python_dev: python3-dev

CentOS_7:
pip: pip
python_dev: python-devel
CentOS_8:
pip: pip3
python_dev: python3-devel

0 comments on commit 3c343f1

Please sign in to comment.