1
1
Fork 0
mirror of https://gitlab.archlinux.org/archlinux/infrastructure.git synced 2024-05-05 17:36:08 +02:00
infrastructure/roles/borg_client/tasks/main.yml
Kristian Klausen 4112bdf9fd Make ansible-lint happy
yaml: truthy value should be one of [false, true] (truthy)
yaml: wrong indentation: expected 4 but found 2 (indentation)
yaml: too few spaces before comment (comments)
yaml: missing starting space in comment (comments)
yaml: too many blank lines (1 > 0) (empty-lines)
yaml: too many spaces after colon (colons)
yaml: comment not indented like content (comments-indentation)
yaml: no new line character at the end of file (new-line-at-end-of-file)
load-failure: Failed to load or parse file
parser-error: couldn't resolve module/action 'hosts'. This often indicates a misspelling, missing collection, or incorrect module path.
2021-02-14 14:22:05 +01:00

69 lines
2.6 KiB
YAML

---
- name: install borg and tools
pacman: name=borg state=present
- name: check if borg repository already exists
command: borg list {{ item['host'] }}/{{ item['dir'] }}
environment:
BORG_RELOCATED_REPO_ACCESS_IS_OK: "yes"
register: borg_list
ignore_errors: true
loop: "{{ backup_hosts }}"
changed_when: borg_list.stdout | length > 0
- name: init borg repository
command: borg init -e keyfile {{ item['host'] }}/{{ item['dir'] }}
when: borg_list is failed
environment:
BORG_PASSPHRASE: ""
ignore_errors: true # This can sometimes fail if a backup is in progress :/
loop: "{{ backup_hosts }}"
- name: install convenience scripts
template: src=borg.j2 dest=/usr/local/bin/borg{{ item['suffix'] }} owner=root group=root mode=0755
loop: "{{ backup_hosts }}"
- name: install borg backup scripts
template: src=borg-backup.sh.j2 dest=/usr/local/bin/borg-backup{{ item['suffix'] }}.sh owner=root group=root mode=0755
loop: "{{ backup_hosts }}"
- name: install postgres backup script
template: src=backup-postgres.sh.j2 dest=/usr/local/bin/backup-postgres.sh owner=root group=root mode=0755
when: postgres_backup_dir is defined
- name: check whether postgres user exists
command: getent passwd postgres
register: check_postgres_user
ignore_errors: true
changed_when: check_postgres_user.stdout | length > 0
- name: make postgres backup directory
file: path={{ postgres_backup_dir }} owner=root group=root mode=0755 state=directory
when: check_postgres_user is succeeded and postgres_backup_dir is defined
- name: install mysql backup script
template: src=backup-mysql.sh.j2 dest=/usr/local/bin/backup-mysql.sh owner=root group=root mode=0755
when: mysql_backup_dir is defined
- name: install mysql backup config
template: src=backup-my.cnf.j2 dest={{ mysql_backup_defaults }} owner=root group=root mode=0644
when: mysql_backup_defaults is defined
- name: create mysql backup directory
file: path={{ mysql_backup_dir }} state=directory owner=root group=root mode=0755
when: mysql_backup_dir is defined
- name: install gitlab backup script
template: src=backup-gitlab.sh.j2 dest=/usr/local/bin/backup-gitlab.sh owner=root group=root mode=0755
when: inventory_hostname == "gitlab.archlinux.org"
- name: install systemd timer and service for backup
copy: src={{ item }} dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644
with_items:
- borg-backup.timer
- borg-backup.service
- borg-backup-offsite.service
- name: activate systemd timers for backup
systemd: name=borg-backup.timer enabled=yes state=started daemon-reload=yes