Refactor the backup tasks into smaller files
This commit is contained in:
parent
da5d6eef8c
commit
e64a267ff3
4 changed files with 55 additions and 53 deletions
16
roles/backup/tasks/backup.d.yml
Normal file
16
roles/backup/tasks/backup.d.yml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
---
|
||||||
|
- 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 }}/*"
|
12
roles/backup/tasks/docker.yml
Normal file
12
roles/backup/tasks/docker.yml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
- 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.
|
|
@ -11,64 +11,18 @@
|
||||||
- name: Import prepare tasks for common service
|
- name: Import prepare tasks for common service
|
||||||
ansible.builtin.import_tasks: tasks/prepare-common-service.yml
|
ansible.builtin.import_tasks: tasks/prepare-common-service.yml
|
||||||
|
|
||||||
- name: Copy the Dockerfile
|
- name: Copy the main backup script
|
||||||
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:
|
ansible.builtin.template:
|
||||||
src: "backup.sh.j2"
|
src: "backup.sh.j2"
|
||||||
dest: "{{ (service_path, 'backup.sh') | path_join }}"
|
dest: "{{ (service_path, 'backup.sh') | path_join }}"
|
||||||
mode: "0755"
|
mode: "0755"
|
||||||
|
|
||||||
- name: Copy the system service
|
- name: Import tasks specific to docker
|
||||||
ansible.builtin.template:
|
ansible.builtin.import_tasks: docker.yml
|
||||||
src: backup.service.j2
|
- name: Import tasks specific to the backup.d scripts
|
||||||
dest: /etc/systemd/system/backup.service
|
ansible.builtin.import_tasks: backup.d.yml
|
||||||
mode: "0644"
|
- name: Import tasks specific to systemd
|
||||||
become: true
|
ansible.builtin.import_tasks: systemd.yml
|
||||||
- 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
|
- name: Build service
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
|
|
20
roles/backup/tasks/systemd.yml
Normal file
20
roles/backup/tasks/systemd.yml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
---
|
||||||
|
- 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
|
Reference in a new issue