diff --git a/containers.yaml b/containers.yaml new file mode 100644 index 0000000..a1e67fb --- /dev/null +++ b/containers.yaml @@ -0,0 +1,12 @@ +- ansible.builtin.git: + repo: https://git.pukeko.xyz/shmick/docker.git + dest: "{{ container_dir }}/{{ item }}" + version: "{{ item }}-cv" + +- ansible.builtin.template: + src: "{{ container_dir }}/{{ item }}/docker-compose.yml.j2" + dest: "{{ container_dir }}/{{ item }}/docker-compose.yml" + +- community.docker.docker_compose: + project_src: "{{ container_dir }}/{{ item }}" + tags: compose diff --git a/docker.yaml b/docker.yaml new file mode 100644 index 0000000..2685a7e --- /dev/null +++ b/docker.yaml @@ -0,0 +1,49 @@ +- name: Set Docker repo architecture + ansible.builtin.set_fact: + docker_arch: "{{ 'amd64' if ansible_architecture == 'x86_64' else 'ansible_architecture' }}" + +- name: Install prerequisites for Docker repository + ansible.builtin.apt: + name: + - ca-certificates + - curl + - gnupg2 + - lsb-release + state: latest + +- name: Add Docker's APT key + ansible.builtin.apt_key: + url: "https://download.docker.com/linux/{{ ansible_distribution|lower }}/gpg" + # ^ ex: Ubuntu -> ubuntu + state: present + + +- name: Add Docker's APT repo + ansible.builtin.apt_repository: + repo: "deb [arch={{ docker_arch }}] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable" + state: present + update_cache: yes + +- name: Install docker and dependencies + ansible.builtin.apt: + name: + - docker-ce + - docker-ce-cli + - containerd.io + - docker-buildx-plugin + - docker-compose-plugin + state: latest + +- name: Start and enable Docker daemon + become: yes + ansible.builtin.service: + name: docker + state: started + enabled: yes + +- name: Start and enable Containerd daemon + become: yes + ansible.builtin.service: + name: containerd + state: started + enabled: yes diff --git a/requirements.yaml b/requirements.yaml new file mode 100644 index 0000000..6635493 --- /dev/null +++ b/requirements.yaml @@ -0,0 +1,3 @@ +collections: + - name: community.general # https://github.com/ansible-collections/community.general + version: latest diff --git a/traefik.yaml b/traefik.yaml index 3ceadf1..0d01620 100644 --- a/traefik.yaml +++ b/traefik.yaml @@ -8,56 +8,7 @@ tasks: - name: Install Docker CE ## From: https://gist.github.com/rbq/886587980894e98b23d0eee2a1d84933, https://docs.docker.com/engine/install/ - block: - - name: Set Docker repo architecture - ansible.builtin.set_fact: - docker_arch: "{{ 'amd64' if ansible_architecture == 'x86_64' else 'ansible_architecture' }}" - - - name: Install prerequisites for Docker repository - ansible.builtin.apt: - name: - - ca-certificates - - curl - - gnupg2 - - lsb-release - state: latest - - - name: Add Docker's APT key - ansible.builtin.apt_key: - url: "https://download.docker.com/linux/{{ ansible_distribution|lower }}/gpg" - # ^ ex: Ubuntu -> ubuntu - state: present - - - - name: Add Docker's APT repo - ansible.builtin.apt_repository: - repo: "deb [arch={{ docker_arch }}] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable" - state: present - update_cache: yes - - - name: Install docker and dependencies - ansible.builtin.apt: - name: - - docker-ce - - docker-ce-cli - - containerd.io - - docker-buildx-plugin - - docker-compose-plugin - state: latest - - - name: Start and enable Docker daemon - become: yes - ansible.builtin.service: - name: docker - state: started - enabled: yes - - - name: Start and enable Containerd daemon - become: yes - ansible.builtin.service: - name: containerd - state: started - enabled: yes + include_tasks: docker.yaml - name: Make sure Container directory exists ansible.builtin.file: @@ -65,22 +16,8 @@ state: directory - name: Set up containers - block: - - ansible.builtin.git: - repo: https://git.pukeko.xyz/shmick/docker.git - dest: "{{ container_dir }}/{{ item }}" - version: "{{ item }}-cv" - - - ansible.builtin.template: - src: "{{ container_dir }}/{{ item }}/docker-compose.yml.j2" - dest: "{{ container_dir }}/{{ item }}/docker-compose.yml" - - - community.docker.docker_compose: - project_src: "{{ container_dir }}/{{ item }}" - tags: compose - - loop: + include_tasks: containers.yaml + with_items: - ddclient - prometheus - traefik -