diff --git a/Makefile b/Makefile index fd5d543..2aa76de 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,7 @@ all: $(MAKE) tofu $(MAKE) dns @printf "\n=====\n\n" + ansible-playbook ./playbooks/stop-and-backup-unused.yml -t $(TAGS) ansible-playbook ./playbooks/serguzim.net.yml -t $(TAGS) visualize: diff --git a/playbooks/filter_plugins/service_filters.py b/playbooks/filter_plugins/service_filters.py index 734e62d..a9d4d6a 100644 --- a/playbooks/filter_plugins/service_filters.py +++ b/playbooks/filter_plugins/service_filters.py @@ -4,6 +4,7 @@ class FilterModule(object): 'my_service_attributes': self.my_service_attributes, 'services_to_dnscontrol': self.services_to_dnscontrol, 'services_get_backups': self.services_get_backups, + 'service_get_backups': self.service_get_backups, 'service_get_domain': self.service_get_domain, } @@ -39,6 +40,11 @@ class FilterModule(object): result.append(backup["name"]) return result + def service_get_backups(self, all_services, wanted_service): + if service := self.find_service(all_services, wanted_service): + return service.get("backup") or [] + return [] + def service_get_domain(self, all_services, wanted_service): if service := self.find_service(all_services, wanted_service): if dns := service.get("dns"): diff --git a/playbooks/tasks/prepare-common-service.yml b/playbooks/tasks/prepare-common-service.yml index ee588a9..9fbc561 100644 --- a/playbooks/tasks/prepare-common-service.yml +++ b/playbooks/tasks/prepare-common-service.yml @@ -6,6 +6,9 @@ ansible.builtin.import_tasks: tasks/steps/template-docker-compose.yml when: compose is defined -- name: Import tasks create a service.env file +- name: Import tasks to create a service.env file ansible.builtin.import_tasks: tasks/steps/template-service-env.yml when: env is defined + +- name: Import tasks to restore volume + ansible.builtin.import_tasks: tasks/restore-volumes.yml diff --git a/playbooks/tasks/restore-volumes.yml b/playbooks/tasks/restore-volumes.yml new file mode 100644 index 0000000..fd7890a --- /dev/null +++ b/playbooks/tasks/restore-volumes.yml @@ -0,0 +1,6 @@ +- name: Restore volumes + ansible.builtin.include_tasks: + file: tasks/steps/restore-volume.yml + loop: "{{ all_services | service_get_backups(role_name) | map(attribute='name') }}" + loop_control: + loop_var: volume_name diff --git a/playbooks/tasks/steps/restore-volume.yml b/playbooks/tasks/steps/restore-volume.yml new file mode 100644 index 0000000..5574995 --- /dev/null +++ b/playbooks/tasks/steps/restore-volume.yml @@ -0,0 +1,16 @@ +- name: Get infos on volume "{{ volume_name }}" + community.docker.docker_volume_info: + name: "{{ volume_name }}" + register: volume_info_result + +- name: Restore volume "{{ volume_name }}" + ansible.builtin.command: + cmd: sudo autorestic -c .autorestic.all.yml restore -l {{ volume_name }} + chdir: "{{ (services_path, 'backup') | path_join }}" + when: not volume_info_result.exists + changed_when: true + become: true + register: cmd_result_backup + until: "cmd_result_backup is not failed" + retries: 10 + delay: 10 diff --git a/services.auto.tfvars b/services.auto.tfvars index a4a0939..e22ddc7 100644 --- a/services.auto.tfvars +++ b/services.auto.tfvars @@ -254,7 +254,7 @@ services = { domain = "s3.serguzim.me" }, { - domain = "s3.serguzim.me" + domain = "console.s3.serguzim.me" name = "minio-console" alias = "minio" } @@ -479,7 +479,7 @@ services = { "vikunja" = { name = "vikunja" - host = "node003" + host = "node001" dns = [{ domain = "todo.serguzim.me" }]