netz39-infra-ansible/roles/docker_setup/tasks/main.yml

85 lines
2.2 KiB
YAML
Raw Normal View History

2020-11-25 16:55:50 +01:00
# 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:
2020-12-28 22:53:53 +01:00
- apt-transport-https
- ca-certificates
- gnupg2
- software-properties-common
2020-11-25 16:55:50 +01:00
- name: add Docker apt-key
apt_key:
url: https://download.docker.com/linux/debian/gpg
state: present
- name: add Docker's APT repository
ansible.builtin.template:
src: templates/docker.list.j2
dest: /etc/apt/sources.list.d/docker.list
register: apt_repo
- name: Update package cache # noqa 503
ansible.builtin.apt:
2020-12-28 22:53:53 +01:00
update_cache: true
when: apt_repo.changed
2020-11-25 16:55:50 +01:00
- name: install Docker
package:
name: "{{ packages }}"
state: present
vars:
packages:
2020-12-28 22:53:53 +01:00
- docker-ce
- python3-docker
2020-11-25 16:55:50 +01:00
- name: Set docker configuration
template:
src: templates/daemon.json.j2
2020-11-25 16:55:50 +01:00
dest: /etc/docker/daemon.json
mode: "0644"
2020-11-25 16:55:50 +01:00
notify: restart docker
- 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"
2020-11-25 16:55:50 +01:00
- name: Place admin users in docker group
user:
name: "{{ item.logname }}"
2020-12-28 22:53:53 +01:00
groups: [docker]
2020-11-25 16:55:50 +01:00
append: yes
2020-12-12 23:10:04 +01:00
when: item.docker
with_items: "{{ users }}"