This repository has been archived on 2022-01-10. You can view files and clone it, but cannot push or open issues or pull requests.
docker/tasks/main.yml

122 lines
3.2 KiB
YAML
Raw Normal View History

2021-11-12 09:16:00 +01:00
- name: "Remove Docker snap package"
community.general.snap:
name: "docker"
state: absent
when:
- ansible_facts['distribution'] == "Ubuntu"
2021-11-12 10:34:43 +01:00
- name: "Add apt key for Ubuntu Docker"
2021-08-30 17:22:41 +02:00
apt_key:
url: "https://download.docker.com/linux/ubuntu/gpg"
state: present
2021-11-12 10:34:43 +01:00
when:
- ansible_facts['distribution'] == "Ubuntu"
2021-08-30 17:22:41 +02:00
2021-11-12 10:34:43 +01:00
- name: "Add Docker Ubuntu repository"
2021-08-30 17:22:41 +02:00
apt_repository:
2021-11-12 10:34:43 +01:00
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
2021-08-30 17:22:41 +02:00
state: present
2021-11-12 10:34:43 +01:00
when:
- ansible_facts['distribution'] == "Ubuntu"
- name: "Add apt key for Debian Docker"
apt_key:
url: "https://download.docker.com/linux/debian/gpg"
state: present
when:
- ansible_facts['distribution'] == "Debian"
- name: "Add Docker Debian repository"
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable"
state: present
when:
- ansible_facts['distribution'] == "Debian"
2021-08-30 17:22:41 +02:00
- name: "Install Docker"
apt:
state: present
2021-08-30 17:35:04 +02:00
pkg:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose
2021-10-25 18:09:32 +02:00
2021-11-15 12:25:59 +01:00
- name: "Install the Docker API"
ansible.builtin.pip:
name: docker
state: latest
2021-10-25 18:09:32 +02:00
- name: "Download lazydocker"
ansible.builtin.get_url:
url: "https://github.com/jesseduffield/lazydocker/releases/download/v{{ docker_lazydocker_version }}/lazydocker_{{ docker_lazydocker_version }}_Linux_x86_64.tar.gz"
dest: "/tmp/lazydocker.tar.gz"
- name: "Extract lazydocker"
ansible.builtin.unarchive:
2021-10-25 19:35:48 +02:00
src: "/tmp/lazydocker.tar.gz"
dest: "/usr/bin/"
2021-10-25 18:09:32 +02:00
mode: "0777"
2021-10-25 19:35:48 +02:00
remote_src: yes
exclude:
- "LICENSE"
- "README.md"
2021-11-10 22:25:38 +01:00
- name: "Get the Systems repository"
ansible.builtin.git:
repo: "https://git.2li.ch/Nebucatnetzer/docker_systems.git"
2021-11-12 10:34:43 +01:00
dest: "/home/{{ ansible_ssh_user }}/docker_systems"
2021-11-10 22:25:38 +01:00
become: no
when: docker_skip_project is undefined
- name: "Get the .env template"
ansible.builtin.fetch:
2021-11-12 10:34:43 +01:00
src: "{{ docker_project_path }}/.env.j2"
dest: "/tmp/fetched/{{ inventory_hostname }}.env.j2"
2021-11-10 22:38:40 +01:00
flat: yes
2021-11-12 10:34:43 +01:00
fail_on_missing: no
register: env_file
2021-11-10 22:25:38 +01:00
become: no
when: docker_skip_project is undefined
- name: "Copy the .env file"
ansible.builtin.template:
2021-11-12 10:34:43 +01:00
src: "/tmp/fetched/{{ inventory_hostname }}.env.j2"
2021-11-10 22:25:38 +01:00
dest: "{{ docker_project_path }}/.env"
become: no
2021-11-12 10:34:43 +01:00
when: docker_skip_project is undefined and env_file.changed
2021-10-26 21:59:00 +02:00
2021-11-11 15:20:27 +01:00
- name: "Open the required UDP ports"
ansible.builtin.ufw:
rule: "allow"
port: "{{ item }}"
proto: "udp"
loop: "{{ docker_udp_ports }}"
when: docker_udp_ports is defined
- name: "Open the required TCP ports"
ansible.builtin.ufw:
rule: "allow"
port: "{{ item }}"
2021-11-11 23:00:09 +01:00
proto: "tcp"
2021-11-11 15:20:27 +01:00
loop: "{{ docker_tcp_ports }}"
when: docker_tcp_ports is defined
2021-10-26 21:59:00 +02:00
- name: "Start the Docker containers"
community.docker.docker_compose:
project_src: "{{ docker_project_path }}"
state: "present"
pull: "yes"
remove_orphans: "yes"
2021-11-10 22:25:38 +01:00
when: docker_skip_project is undefined
2021-11-12 16:53:53 +01:00
- name: "Prune old data"
community.docker.docker_prune:
containers: yes
images: yes
images_filters:
dangling: true
networks: yes
volumes: yes
builder_cache: yes