From 26a77be80bdb82c9ccb42783fe0bbecf5903879a Mon Sep 17 00:00:00 2001 From: saibotk Date: Sat, 2 Jan 2021 04:39:35 +0100 Subject: [PATCH] docker: Add Ubuntu / Debian support --- roles/docker/README.md | 4 +-- roles/docker/defaults/main.yml | 35 ++++++++++++++------ roles/docker/meta/main.yml | 6 ++-- roles/docker/tasks/Debian.yml | 58 +++++++++++++++++++++++++++++++++ roles/docker/tasks/RedHat.yml | 59 ++++++++++++++++++++++++++++++++++ roles/docker/tasks/main.yml | 35 ++++++-------------- 6 files changed, 157 insertions(+), 40 deletions(-) create mode 100644 roles/docker/tasks/Debian.yml create mode 100644 roles/docker/tasks/RedHat.yml diff --git a/roles/docker/README.md b/roles/docker/README.md index a1faef0..49e6a15 100644 --- a/roles/docker/README.md +++ b/roles/docker/README.md @@ -6,7 +6,7 @@ This will install [Docker](https://www.docker.com/) from their official reposito Requirements ------------ -You will need to have the EPEL repository enabled (eg. by installing the `epel-release` package). +For CentOS: You will need to have the EPEL repository enabled (eg. by installing the `epel-release` package). Role Variables -------------- @@ -18,7 +18,7 @@ Role Variables Dependencies ------------ -- epel +- epel (for CentOS) License ------- diff --git a/roles/docker/defaults/main.yml b/roles/docker/defaults/main.yml index e4ac363..a39b5c9 100644 --- a/roles/docker/defaults/main.yml +++ b/roles/docker/defaults/main.yml @@ -4,6 +4,7 @@ # Infrastructure # Ansible instructions to deploy the infrastructure # Copyright (C) 2020 Saibotk +# Copyright (C) 2020 nickjj (https://github.com/nickjj/ansible-docker) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,6 +18,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# Architecture mapping for apt repositories +docker_apt_architecture_map: + "x86_64": "amd64" + "aarch64": "arm64" + "aarch": "arm64" + "armhf": "armhf" + "armv7l": "armhf" + # Edition can be one of: 'ce' (Community Edition) or 'ee' (Enterprise Edition). docker_edition: 'ce' @@ -28,26 +37,32 @@ docker_package_state: present docker_service_state: started docker_service_enabled: true +# Should the official docker repository be installed? +docker_install_repository: true + # The repository settings -# The repository will be added as a yum repository to allow downloading/installing the package -docker_yum_repo_url: https://download.docker.com/linux/centos/docker-{{ docker_edition }}.repo -docker_yum_repo_enable_edge: '0' -docker_yum_repo_enable_test: '0' +# The repository will be added as a repository to allow downloading/installing the package +docker_yum_repository_url: https://download.docker.com/linux/centos/docker-{{ docker_edition }}.repo +docker_yum_repository_destination: /etc/yum.repos.d/docker-{{ docker_edition }}.repo # Where to fetch the docker repository GPG key from -docker_yum_gpg_key: https://download.docker.com/linux/centos/gpg +docker_yum_repository_gpg_key: https://download.docker.com/linux/centos/gpg + +# The apt repository settings +docker_apt_key_id: "9DC858229FC7DD38854AE2D88D81803C0EBFCD88" +docker_apt_key_url: "https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg" +docker_apt_repository: > + deb [arch={{ docker_apt_architecture_map[ansible_architecture] }}] + https://download.docker.com/linux/{{ ansible_distribution | lower }} + {{ ansible_distribution_release }} stable # Should the python package for docker be installed via pip? docker_python_package_install: true # Where should it be installed? (Note: This will be installed as a standalone without breaking system dependencies) docker_python_package_path: /opt/ansible-dependencies -# The name of the package to install pip via yum -docker_python_pip_package: "python-pip" +# The package states of needed packages to install for the python libraries docker_python_pip_package_state: "present" - -# The name of the package to install virtualenv via yum -docker_python_virtualenv_package: "python-virtualenv" docker_python_virtualenv_package_state: "present" # The pip package name of the docker library diff --git a/roles/docker/meta/main.yml b/roles/docker/meta/main.yml index af36b3f..f2227e4 100644 --- a/roles/docker/meta/main.yml +++ b/roles/docker/meta/main.yml @@ -8,8 +8,10 @@ galaxy_info: - name: CentOS versions: - 7 + - name: Ubuntu + versions: + - 20.04 galaxy_tags: [] -dependencies: - - epel +dependencies: [] diff --git a/roles/docker/tasks/Debian.yml b/roles/docker/tasks/Debian.yml new file mode 100644 index 0000000..612227e --- /dev/null +++ b/roles/docker/tasks/Debian.yml @@ -0,0 +1,58 @@ +--- +# Tasks file for the docker role + +# Infrastructure +# Ansible instructions to deploy the infrastructure +# +# Copyright (C) 2020 Saibotk +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +- name: Ensure dependencies are installed. + apt: + name: + - apt-transport-https + - ca-certificates + - gnupg2 + state: present + become: true + +- name: Add Docker GPG key. + apt_key: + id: "{{ docker_apt_key_id }}" + url: "{{ docker_apt_key_url }}" + state: present + when: + - docker_install_repository + become: true + +- name: Add Docker repository. + apt_repository: + repo: "{{ docker_apt_repository }}" + update_cache: true + when: + - docker_install_repository + become: true + +- name: Ensure pip & virtualenv are installed. + package: + name: "{{ item.name }}" + state: "{{ item.state }}" + loop: + - name: "python3-pip" + state: "{{ docker_python_pip_package_state }}" + - name: "python3-virtualenv" + state: "{{ docker_python_virtualenv_package_state }}" + when: + - docker_python_package_install + become: true diff --git a/roles/docker/tasks/RedHat.yml b/roles/docker/tasks/RedHat.yml new file mode 100644 index 0000000..4c5b412 --- /dev/null +++ b/roles/docker/tasks/RedHat.yml @@ -0,0 +1,59 @@ +--- +# Tasks file for the docker role + +# Infrastructure +# Ansible instructions to deploy the infrastructure +# +# Copyright (C) 2020 Saibotk +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +- name: Ensure old versions of Docker are not installed. + package: + name: + - docker + - docker-common + - docker-engine + state: absent + +- name: Add Docker GPG key. + rpm_key: + key: "{{ docker_yum_repository_gpg_key }}" + state: present + when: + - docker_install_repository + become: true + +- name: Add Docker repository. + get_url: + url: "{{ docker_yum_repository_url }}" + dest: "{{ docker_yum_repository_destination }}" + owner: root + group: root + mode: '0644' + when: + - docker_install_repository + become: true + +- name: Ensure pip & virtualenv are installed. + package: + name: "{{ item.name }}" + state: "{{ item.state }}" + loop: + - name: "python-pip" + state: "{{ docker_python_pip_package_state }}" + - name: "python-virtualenv" + state: "{{ docker_python_virtualenv_package_state }}" + when: + - docker_python_package_install + become: true diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml index 5f0b9dd..40a1195 100644 --- a/roles/docker/tasks/main.yml +++ b/roles/docker/tasks/main.yml @@ -3,6 +3,7 @@ # Infrastructure # Ansible instructions to deploy the infrastructure +# Copyright (C) 2019-2020 Christoph (Sheogorath) Kern # Copyright (C) 2020 Saibotk # # This program is free software: you can redistribute it and/or modify @@ -17,20 +18,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -- name: Add Docker GPG key. - rpm_key: - key: "{{ docker_yum_gpg_key }}" - state: present - become: true - -- name: Add Docker repository. - get_url: - url: "{{ docker_yum_repo_url }}" - dest: '/etc/yum.repos.d/docker-{{ docker_edition }}.repo' - owner: root - group: root - mode: '0644' - become: true +- name: "Select tasks for {{ ansible_distribution }} {{ ansible_distribution_major_version }}" + include_tasks: "{{ distro_file }}" + with_first_found: + - "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml" + - "{{ ansible_distribution }}.yml" + - "{{ ansible_os_family }}.yml" + loop_control: + loop_var: distro_file - name: Install Docker. package: @@ -49,18 +44,6 @@ - name: Ensure handlers are notified now to avoid firewall conflicts. meta: flush_handlers -- name: Ensure pip & virtualenv is installed. - package: - name: "{{ item.name }}" - state: "{{ item.state }}" - become: true - loop: - - name: "{{ docker_python_pip_package }}" - state: "{{ docker_python_pip_package_state }}" - - name: "{{ docker_python_virtualenv_package }}" - state: "{{ docker_python_virtualenv_package_state }}" - when: docker_python_package_install - - name: Install docker python package. pip: name: "{{ docker_pip_package }}"