mirror of
https://gitverse.ru/kpa39l/infrastructure.git
synced 2026-09-29 18:15:02 +00:00
97 lines
2.8 KiB
YAML
97 lines
2.8 KiB
YAML
---
|
|
- name: Install prerequisites for Docker
|
|
apt:
|
|
name:
|
|
- apt-transport-https
|
|
- ca-certificates
|
|
- curl
|
|
- gnupg
|
|
- lsb-release
|
|
state: present
|
|
update_cache: yes
|
|
ignore_errors: yes # Игнорируем ошибки, если старые репо битые
|
|
|
|
- name: Install software-properties-common on Ubuntu
|
|
apt:
|
|
name: software-properties-common
|
|
state: present
|
|
when: ansible_distribution == "Ubuntu"
|
|
ignore_errors: yes
|
|
|
|
- name: Create keyrings directory
|
|
file:
|
|
path: /etc/apt/keyrings
|
|
state: directory
|
|
mode: '0755'
|
|
|
|
# --- Логика для UBUNTU ---
|
|
- name: Download Docker GPG key for Ubuntu
|
|
shell: |
|
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
|
|
chmod a+r /etc/apt/keyrings/docker.asc
|
|
args:
|
|
creates: /etc/apt/keyrings/docker.asc
|
|
when: ansible_distribution == "Ubuntu"
|
|
|
|
- name: Add Docker repository for Ubuntu
|
|
copy:
|
|
# Используем переменную Ansible для архитектуры, чтобы избежать shell-синтаксиса в файле
|
|
content: "deb [arch={{ ansible_architecture }} signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable\n"
|
|
dest: /etc/apt/sources.list.d/docker.list
|
|
mode: '0644'
|
|
when: ansible_distribution == "Ubuntu"
|
|
|
|
# --- Логика для DEBIAN ---
|
|
- name: Download and convert Docker GPG key for Debian
|
|
shell: |
|
|
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
|
args:
|
|
creates: /usr/share/keyrings/docker-archive-keyring.gpg
|
|
when: ansible_distribution == "Debian"
|
|
|
|
- name: Add Docker repository for Debian
|
|
copy:
|
|
content: "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable\n"
|
|
dest: /etc/apt/sources.list.d/docker.list
|
|
mode: '0644'
|
|
when: ansible_distribution == "Debian"
|
|
|
|
- name: Update apt cache after adding Docker repo
|
|
apt:
|
|
update_cache: yes
|
|
|
|
- name: Install Docker packages
|
|
apt:
|
|
name:
|
|
- docker-ce
|
|
- docker-ce-cli
|
|
- containerd.io
|
|
- docker-buildx-plugin
|
|
- docker-compose-plugin
|
|
state: present
|
|
update_cache: yes
|
|
|
|
- name: Ensure Garage directory exists
|
|
file:
|
|
path: /opt/garage
|
|
state: directory
|
|
mode: '0755'
|
|
|
|
- name: Deploy Garage docker-compose.yml
|
|
template:
|
|
src: docker-compose.yml.j2
|
|
dest: /opt/garage/docker-compose.yml
|
|
mode: '0644'
|
|
|
|
- name: Deploy Garage configuration (garage.toml)
|
|
template:
|
|
src: garage.toml.j2
|
|
dest: /opt/garage/garage.toml
|
|
mode: '0644'
|
|
notify: Restart Garage
|
|
|
|
- name: Start Garage services
|
|
community.docker.docker_compose_v2:
|
|
project_src: /opt/garage
|
|
state: present
|