Fix syntax error and refactor.

This commit is contained in:
yohan 2023-10-22 16:00:58 +02:00
parent c5d46259d8
commit 118dcf0f78
3 changed files with 10 additions and 34 deletions

View File

@ -7,11 +7,6 @@
ansible.builtin.include_tasks: "tasks/assert_var_not_empty.yml" ansible.builtin.include_tasks: "tasks/assert_var_not_empty.yml"
with_items: "{{ BACKUP_OVH1_REQUIRED_VARS }}" with_items: "{{ BACKUP_OVH1_REQUIRED_VARS }}"
- name: Create backup directory
ansible.builtin.file:
path: "{{ WORKDIR }}/backup"
state: directory
- name: Archive volumes - name: Archive volumes
ansible.builtin.command: "tar -czf {{ WORKDIR }}/backup/{{ item }}.tar.gz -C /mnt/volumes {{ item }}" ansible.builtin.command: "tar -czf {{ WORKDIR }}/backup/{{ item }}.tar.gz -C /mnt/volumes {{ item }}"
with_items: "{{ BACKUP_OVH1_VOLUMES }}" with_items: "{{ BACKUP_OVH1_VOLUMES }}"
@ -28,12 +23,6 @@
ansible.builtin.command: "tar -czf {{ WORKDIR }}/backup/mysql-server_dumps.tar.gz -C /mnt/volumes {{ MySQL_dump.stdout_lines | last }} {{ DBs_dump.stdout_lines | last }}" ansible.builtin.command: "tar -czf {{ WORKDIR }}/backup/mysql-server_dumps.tar.gz -C /mnt/volumes {{ MySQL_dump.stdout_lines | last }} {{ DBs_dump.stdout_lines | last }}"
with_items: "{{ BACKUP_OVH1_VOLUMES }}" with_items: "{{ BACKUP_OVH1_VOLUMES }}"
thon3-swiftclient is a requirement of duplicity
- name: Install python3-swiftclient
ansible.builtin.package:
name: python3-swiftclient
state: present
- name: Backup with duplicity - name: Backup with duplicity
ansible.builtin.command: "duplicity --num-retries 3 --full-if-older-than 1M --progress --archive-dir {{ ARCHIVE_DIR }} --name {{ lookup('env','BACKUP_WORKFLOW') }} --allow-source-mismatch '{{ WORKDIR }}/backup' swift://{{ lookup('env','BACKUP_WORKFLOW') }}" ansible.builtin.command: "duplicity --num-retries 3 --full-if-older-than 1M --progress --archive-dir {{ ARCHIVE_DIR }} --name {{ lookup('env','BACKUP_WORKFLOW') }} --allow-source-mismatch '{{ WORKDIR }}/backup' swift://{{ lookup('env','BACKUP_WORKFLOW') }}"
environment: "{{ DUPLICITY_ENVIRONMENT }}" environment: "{{ DUPLICITY_ENVIRONMENT }}"

View File

@ -12,11 +12,6 @@
url: "https://{{ CLOUD_SERVER }}/s/{{ lookup('env','KEY') }}/download?path=%2F&files=secrets.tar.gz.enc" url: "https://{{ CLOUD_SERVER }}/s/{{ lookup('env','KEY') }}/download?path=%2F&files=secrets.tar.gz.enc"
dest: "{{ WORKDIR }}/secrets.tar.gz.enc" dest: "{{ WORKDIR }}/secrets.tar.gz.enc"
- name: Install openssh-client
ansible.builtin.package:
name: openssh-client
state: present
- name: Create /root/.ssh directory - name: Create /root/.ssh directory
ansible.builtin.file: ansible.builtin.file:
path: /root/.ssh path: /root/.ssh
@ -99,11 +94,6 @@
dest: "{{ WORKDIR }}/{{ item }}" dest: "{{ WORKDIR }}/{{ item }}"
with_items: "{{ BOOTSTRAP_REPOS }}" with_items: "{{ BOOTSTRAP_REPOS }}"
- name: Create backup directory
ansible.builtin.file:
path: "{{ WORKDIR }}/backup"
state: directory
- name: Archive Git repository - name: Archive Git repository
ansible.builtin.command: "tar -czf {{ WORKDIR }}/backup/{{ item }}.tar.gz -C {{ WORKDIR }} {{ item }}" ansible.builtin.command: "tar -czf {{ WORKDIR }}/backup/{{ item }}.tar.gz -C {{ WORKDIR }} {{ item }}"
with_items: "{{ BOOTSTRAP_REPOS }}" with_items: "{{ BOOTSTRAP_REPOS }}"
@ -113,12 +103,6 @@
src: "{{ WORKDIR }}/secrets.tar.gz.enc" src: "{{ WORKDIR }}/secrets.tar.gz.enc"
dest: "{{ WORKDIR }}/backup/secrets.tar.gz.enc" dest: "{{ WORKDIR }}/backup/secrets.tar.gz.enc"
thon3-swiftclient is a requirement of duplicity
- name: Install python3-swiftclient
ansible.builtin.package:
name: python3-swiftclient
state: present
- name: Backup with duplicity - name: Backup with duplicity
ansible.builtin.command: "duplicity --num-retries 3 --full-if-older-than 1M --progress --archive-dir {{ ARCHIVE_DIR }} --name {{ lookup('env','BACKUP_WORKFLOW') }} --allow-source-mismatch '{{ WORKDIR }}/backup' swift://{{ lookup('env','BACKUP_WORKFLOW') }}" ansible.builtin.command: "duplicity --num-retries 3 --full-if-older-than 1M --progress --archive-dir {{ ARCHIVE_DIR }} --name {{ lookup('env','BACKUP_WORKFLOW') }} --allow-source-mismatch '{{ WORKDIR }}/backup' swift://{{ lookup('env','BACKUP_WORKFLOW') }}"
environment: "{{ DUPLICITY_ENVIRONMENT }}" environment: "{{ DUPLICITY_ENVIRONMENT }}"

View File

@ -8,9 +8,13 @@
url: "https://{{ CLOUD_SERVER }}/s/{{ lookup('env','KEY') }}/download?path=%2F&files=secrets.tar.gz.enc" url: "https://{{ CLOUD_SERVER }}/s/{{ lookup('env','KEY') }}/download?path=%2F&files=secrets.tar.gz.enc"
dest: /root/secrets.tar.gz.enc dest: /root/secrets.tar.gz.enc
- name: Install openssh-client # python3-swiftclient is a requirement of duplicity
- name: Install package requirements
ansible.builtin.package: ansible.builtin.package:
name: openssh-client name:
- git
- python3-swiftclient
- openssh-client
state: present state: present
- name: Create /root/.ssh directory - name: Create /root/.ssh directory
@ -114,11 +118,6 @@
- name: duplicity_cache - name: duplicity_cache
size: 5 size: 5
- name: Install git
ansible.builtin.package:
name: git
state: present
- name: Install jsondiff from pip - name: Install jsondiff from pip
ansible.builtin.pip: ansible.builtin.pip:
name: jsondiff name: jsondiff
@ -126,3 +125,7 @@
delegate_to: 172.17.0.1 delegate_to: 172.17.0.1
become: true become: true
- name: Create backup directory
ansible.builtin.file:
path: "{{ WORKDIR }}/backup"
state: directory