From fb0f058103815bca36b5cbfd8ac4e7b857db43f6 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Tue, 24 Nov 2020 19:31:13 +0100 Subject: [PATCH 1/2] Add docker tasks --- tasks/docker.yml | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tasks/docker.yml diff --git a/tasks/docker.yml b/tasks/docker.yml new file mode 100644 index 0000000..980ae20 --- /dev/null +++ b/tasks/docker.yml @@ -0,0 +1,91 @@ +# This file is a mash-up of: +# https://github.com/geerlingguy/ansible-role-docker/blob/master/tasks/docker-compose.yml +# https://www.digitalocean.com/community/tutorials/how-to-install-docker-compose-on-debian-9 +# and our own stuff … +--- +- name: Gather package facts + package_facts: + manager: "auto" + +- name: Exit if docker.io is installed + fail: + msg: "Please remove docker.io (Debian vanilla docker package) first!" + when: "'docker.io' in ansible_facts.packages" + +- name: Install Docker APT deps + package: + name: "{{ packages }}" + state: present + vars: + packages: + - apt-transport-https + - ca-certificates + - gnupg2 + - software-properties-common + +- name: add Docker apt-key + apt_key: + url: https://download.docker.com/linux/debian/gpg + state: present + +- name: add Docker's APT repository + apt_repository: + repo: deb https://download.docker.com/linux/debian buster stable + state: present + update_cache: true + filename: 'docker' + +- name: install Docker + package: + name: "{{ packages }}" + state: present + vars: + packages: + - docker-ce + +- name: Set docker configuration + copy: + dest: /etc/docker/daemon.json + content: | + { + "exec-opts": ["native.cgroupdriver=systemd"], + "log-driver": "json-file", + "log-opts": { + "max-size": "100m" + } + } + register: docker_config + +- name: Restart docker for changed configuration + service: + name: docker + state: restarted + enabled: yes + when: docker_config.changed + +- name: Check current docker-compose version. + command: docker-compose --version + register: docker_compose_current_version + changed_when: false + failed_when: false + +- name: Delete existing docker-compose version if it's different. + file: + path: "{{ docker_compose_path }}" + state: absent + when: > + docker_compose_current_version.stdout is defined + and docker_compose_version not in docker_compose_current_version.stdout + +- name: Install Docker Compose (if configured). + get_url: + url: https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64 + dest: "{{ docker_compose_path }}" + mode: 0755 + +- name: Place admin users in docker group + user: + name: "{{ item }}" + groups: docker + append: yes + with_items: "{{ admin_users }}" From 3d89bf119e72d2522ea7ef6403d27fd9172d619f Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Tue, 24 Nov 2020 19:31:27 +0100 Subject: [PATCH 2/2] Call docker tasks --- main.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/main.yml b/main.yml index 17e72f6..f945551 100644 --- a/main.yml +++ b/main.yml @@ -3,9 +3,13 @@ become: true vars: - - server_admin: "admin@netz39.de" - - admin_users: [tux, alex] - - ag_timezone: Europe/Berlin + server_admin: "admin@netz39.de" + admin_users: [tux, alex] + + ag_timezone: Europe/Berlin + + docker_compose_version: "1.25.4" + docker_compose_path: /usr/local/bin/docker-compose roles: - role: ansible.timezone @@ -35,5 +39,8 @@ - name: Setup users include_tasks: tasks/users.yml + - name: Setup Docker + include_tasks: tasks/docker.yml + - name: Setup httpd include_tasks: tasks/httpd.yml