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

107 lines
2.9 KiB
YAML

- name: "Remove Docker snap package"
community.general.snap:
name: "docker"
state: absent
when:
- ansible_facts['distribution'] == "Ubuntu"
- name: "Add apt key for Ubuntu Docker"
apt_key:
url: "https://download.docker.com/linux/ubuntu/gpg"
state: present
when:
- ansible_facts['distribution'] == "Ubuntu"
- name: "Add Docker Ubuntu repository"
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
state: present
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"
- name: "Install Docker"
apt:
state: present
pkg:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose
- 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:
src: "/tmp/lazydocker.tar.gz"
dest: "/usr/bin/"
mode: "0777"
remote_src: yes
exclude:
- "LICENSE"
- "README.md"
- name: "Get the Systems repository"
ansible.builtin.git:
repo: "https://git.2li.ch/Nebucatnetzer/docker_systems.git"
dest: "/home/{{ ansible_ssh_user }}/docker_systems"
become: no
when: docker_skip_project is undefined
- name: "Get the .env template"
ansible.builtin.fetch:
src: "{{ docker_project_path }}/.env.j2"
dest: "/tmp/fetched/{{ inventory_hostname }}.env.j2"
flat: yes
fail_on_missing: no
register: env_file
become: no
when: docker_skip_project is undefined
- name: "Copy the .env file"
ansible.builtin.template:
src: "/tmp/fetched/{{ inventory_hostname }}.env.j2"
dest: "{{ docker_project_path }}/.env"
become: no
when: docker_skip_project is undefined and env_file.changed
- 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 }}"
proto: "tcp"
loop: "{{ docker_tcp_ports }}"
when: docker_tcp_ports is defined
- name: "Start the Docker containers"
community.docker.docker_compose:
project_src: "{{ docker_project_path }}"
state: "present"
pull: "yes"
remove_orphans: "yes"
when: docker_skip_project is undefined