add docker

This commit is contained in:
2023-04-20 17:06:11 +05:30
parent a03de1ebdf
commit 32b16c0921
7 changed files with 108 additions and 25 deletions

View File

@@ -0,0 +1,35 @@
---
- name: Copy docker-compose templates for the service
ansible.builtin.template:
src: ../compose/{{item}}/compose.yml.j2
dest: /opt/docker/{{item}}/compose.yml
backup: yes
register: check_status
- name: check if extras file exists for the service
local_action: stat path=../compose/{{item}}/extras.conf.j2
register: file
- name: Copy extras file
ansible.builtin.template:
src: ../compose/{{item}}/extras.conf.j2
dest: /opt/docker/{{item}}/extras.conf
backup: yes
when: file.stat.exists
- name: "Update docker service image"
command:
chdir: "/opt/docker/{{ item }}"
cmd: docker compose pull
when: check_status is changed
- name: "Stop docker service"
command:
chdir: "/opt/docker/{{ item }}"
cmd: docker compose down
when: check_status is changed
- name: "Start docker service"
command:
chdir: "/opt/docker/{{ item }}"
cmd: docker compose up -d --build --remove-orphans
when: check_status is changed

View File

@@ -1,27 +1,14 @@
---
- hosts: all
vars:
docker_services:
- libreddit
- teddit
tasks:
- name: Remove old compose files
ansible.builtin.file:
path: /opt/docker/{{item}}
state: absent
with_fileglob:
- "/home/arya/projects/ansibletest/compose/*"
- name: Copy compose files
copy:
src: /home/arya/projects/ansibletest/compose/{{item}}
dest: /opt/docker/
with_fileglob:
- "/home/arya/projects/ansibletest/compose/*"
- name: stop compose
docker_compose:
project_src: /opt/docker/{{item}}
state: absent
with_fileglob:
- "/home/arya/projects/ansibletest/compose/*"
- name: start compose
docker_compose:
project_src: /opt/docker/{{item}}
state: present
with_fileglob:
- "/home/arya/projects/ansibletest/compose/*"
#
# community.docker does not support compose 2.0 right now.
# https://github.com/ansible-collections/community.docker/issues/216
#
- name: Update docker compose files and restart those with changes
include_tasks: docker-tasks.yaml
with_items: "{{ docker_services }}"