2023-12-16 01:25:14 +00:00
|
|
|
---
|
|
|
|
- name: Set common facts
|
|
|
|
ansible.builtin.import_tasks: tasks/set-default-facts.yml
|
|
|
|
|
|
|
|
- name: Deploy {{ svc.name }}
|
|
|
|
vars:
|
|
|
|
svc: "{{ backup_svc }}"
|
|
|
|
env: "{{ backup_env }}"
|
|
|
|
compose: "{{ backup_compose }}"
|
|
|
|
block:
|
|
|
|
- name: Import prepare tasks for common service
|
|
|
|
ansible.builtin.import_tasks: tasks/prepare-common-service.yml
|
|
|
|
|
|
|
|
- name: Copy the Dockerfile
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: Dockerfile
|
|
|
|
dest: "{{ (service_path, 'Dockerfile') | path_join }}"
|
|
|
|
mode: "0644"
|
|
|
|
register: cmd_result
|
|
|
|
|
|
|
|
- name: Set the docker rebuild flag
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
docker_rebuild: true
|
|
|
|
when: cmd_result.changed # noqa: no-handler We need to handle the restart per service. Handlers don't support variables.
|
|
|
|
|
|
|
|
- name: Set backup.d path
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
backup_d_path: "{{ (service_path, 'backup.d') | path_join }}"
|
|
|
|
|
|
|
|
- name: Create backup.d directory
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ backup_d_path }}"
|
|
|
|
state: directory
|
|
|
|
mode: "0755"
|
|
|
|
|
|
|
|
- name: Copy the additional backup scripts
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: "{{ item }}"
|
|
|
|
dest: "{{ backup_d_path }}"
|
|
|
|
mode: "0755"
|
|
|
|
with_fileglob:
|
|
|
|
- "{{ ansible_facts.hostname }}/*"
|
|
|
|
|
|
|
|
- name: Copy the main backup scripts
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: "backup.sh.j2"
|
|
|
|
dest: "{{ (service_path, 'backup.sh') | path_join }}"
|
|
|
|
mode: "0755"
|
|
|
|
|
|
|
|
- name: Copy the system service
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: backup.service.j2
|
|
|
|
dest: /etc/systemd/system/backup.service
|
|
|
|
mode: "0644"
|
|
|
|
become: true
|
|
|
|
- name: Copy the system timer
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: backup.timer
|
|
|
|
dest: /etc/systemd/system/backup.timer
|
|
|
|
mode: "0644"
|
|
|
|
become: true
|
|
|
|
- name: Enable the system timer
|
|
|
|
ansible.builtin.systemd_service:
|
|
|
|
name: backup.timer
|
|
|
|
state: started
|
|
|
|
enabled: true
|
|
|
|
daemon_reload: true
|
|
|
|
become: true
|
|
|
|
|
|
|
|
- name: Import tasks create a service.env file
|
|
|
|
ansible.builtin.import_tasks: tasks/steps/template-service-env.yml
|
|
|
|
|
|
|
|
- name: Build service
|
|
|
|
ansible.builtin.command:
|
|
|
|
cmd: docker compose build --pull
|
|
|
|
chdir: "{{ service_path }}"
|
|
|
|
register: cmd_result
|
2023-12-18 01:17:09 +00:00
|
|
|
when: docker_rebuild
|
|
|
|
changed_when: true
|
2023-12-16 01:25:14 +00:00
|
|
|
|
|
|
|
- name: Verify service
|
|
|
|
ansible.builtin.command:
|
|
|
|
cmd: docker compose run --rm app check
|
|
|
|
chdir: "{{ service_path }}"
|
|
|
|
changed_when: false
|