From 75acd59ee89248f8e61167ba34a6750603d556a1 Mon Sep 17 00:00:00 2001 From: Julian Schacher Date: Fri, 24 Nov 2023 13:37:40 +0100 Subject: [PATCH] Add docker role for making sure Docker is installed Add a docker role for making sure Docker is installed from the Docker repositories. Take the role from the ccchh-ansible repo, provide attribution in the README and add the relevant license in a new licenses directory. Modify the role by removing the distribution check and adjusting the task names to be in line with other task names in this repo. --- README.md | 6 ++++++ licenses/ccchh-ansible_mit_license | 21 +++++++++++++++++++ playbooks/roles/docker/README.md | 21 +++++++++++++++++++ playbooks/roles/docker/tasks/main.yaml | 7 +++++++ .../docker/tasks/main/01_repo_setup.yaml | 15 +++++++++++++ .../docker/tasks/main/02_docker_install.yaml | 11 ++++++++++ 6 files changed, 81 insertions(+) create mode 100644 README.md create mode 100644 licenses/ccchh-ansible_mit_license create mode 100644 playbooks/roles/docker/README.md create mode 100644 playbooks/roles/docker/tasks/main.yaml create mode 100644 playbooks/roles/docker/tasks/main/01_repo_setup.yaml create mode 100644 playbooks/roles/docker/tasks/main/02_docker_install.yaml diff --git a/README.md b/README.md new file mode 100644 index 0000000..f90bcf4 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# cit Ansible Infrastructure + +## Open Source Software Used + +Source code of the [docker role](playbooks/roles/docker) was taken from the [ccchh-ansible repo](https://gitlab.hamburg.ccc.de/ccchh/thinkcccentre-ansible), where it was licensed under the MIT license. +A copy of the license can be found under [`licenses/ccchh-ansible_mit_license`](licenses/ccchh-ansible_mit_license). diff --git a/licenses/ccchh-ansible_mit_license b/licenses/ccchh-ansible_mit_license new file mode 100644 index 0000000..839f8c1 --- /dev/null +++ b/licenses/ccchh-ansible_mit_license @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 ccchh + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/playbooks/roles/docker/README.md b/playbooks/roles/docker/README.md new file mode 100644 index 0000000..0c6667a --- /dev/null +++ b/playbooks/roles/docker/README.md @@ -0,0 +1,21 @@ +# Role `docker` + +Makes sure Docker Engine and other related packages are installed from the Docker repos on the specified hosts. +For details see: [`tasks/main/02_docker_install.yaml`](./tasks/main/02_docker_install.yaml). + +## Required Arguments + +None. + +## Updates + +This role doesn't handle updates. +However it uses the system package manager for installing Docker Engine and the other related packages, so when you're making sure the system packages are up-to-date, you're handling updates for the packages installed by this role as well. + +## `hosts` + +The `hosts` for this role need to be the machines for which you want to make sure Docker Engine and other related packages are installed from the Docker repos. + +## Links & Resources + +- diff --git a/playbooks/roles/docker/tasks/main.yaml b/playbooks/roles/docker/tasks/main.yaml new file mode 100644 index 0000000..502a9c6 --- /dev/null +++ b/playbooks/roles/docker/tasks/main.yaml @@ -0,0 +1,7 @@ +- name: Ensure the Docker repo is setup + ansible.builtin.import_tasks: + file: main/01_repo_setup.yaml + +- name: Ensure Docker Engine and other related packages are installed + ansible.builtin.import_tasks: + file: main/02_docker_install.yaml diff --git a/playbooks/roles/docker/tasks/main/01_repo_setup.yaml b/playbooks/roles/docker/tasks/main/01_repo_setup.yaml new file mode 100644 index 0000000..30ffd07 --- /dev/null +++ b/playbooks/roles/docker/tasks/main/01_repo_setup.yaml @@ -0,0 +1,15 @@ +- name: Ensure Dockers GPG key is added + ansible.builtin.get_url: + url: https://download.docker.com/linux/debian/gpg + dest: /etc/apt/trusted.gpg.d/docker.asc + mode: "0644" + owner: root + group: root + become: true + +- name: Ensure Dockers APT repository is added + ansible.builtin.apt_repository: + repo: "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/docker.asc] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable" + filename: docker + state: present + become: true diff --git a/playbooks/roles/docker/tasks/main/02_docker_install.yaml b/playbooks/roles/docker/tasks/main/02_docker_install.yaml new file mode 100644 index 0000000..f2ae880 --- /dev/null +++ b/playbooks/roles/docker/tasks/main/02_docker_install.yaml @@ -0,0 +1,11 @@ +- name: Ensure Docker Engine and other related packages are installed + ansible.builtin.apt: + name: + - docker-ce + - docker-ce-cli + - containerd.io + - docker-buildx-plugin + - docker-compose-plugin + state: present + update_cache: true + become: true