Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

etcd/backup: native ansible modules instead of shell #10540

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions roles/etcd/handlers/backup_cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
- name: Cleanup etcd backups
command: /bin/true
notify:
- Find old etcd backups
- Remove old etcd backups

- name: Find old etcd backups
ansible.builtin.find:
file_type: directory
recurse: false
paths: "{{ etcd_backup_prefix }}"
patterns: "etcd-*"
register: _etcd_backups
when: etcd_backup_retention_count >= 0

- name: Remove old etcd backups
shell:
chdir: "{{ etcd_backup_prefix }}"
cmd: "set -o pipefail && find . -name 'etcd-*' -type d | sort -n | head -n -{{ etcd_backup_retention_count }} | xargs rm -rf"
executable: /bin/bash
ansible.builtin.file:
state: absent
path: "{{ item }}"
loop: "{{ (_etcd_backups.files | sort(attribute='ctime', reverse=True))[etcd_backup_retention_count:] | map(attribute='path') }}"
when: etcd_backup_retention_count >= 0