You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6 KiB

  1. ---
  2. - name: Backup etcd data
  3. command: /bin/true
  4. notify:
  5. - Refresh Time Fact
  6. - Set Backup Directory
  7. - Create Backup Directory
  8. - Stat etcd v2 data directory
  9. - Backup etcd v2 data
  10. - Backup etcd v3 data
  11. when: etcd_cluster_is_healthy.rc == 0
  12. - name: Refresh Time Fact
  13. setup: filter=ansible_date_time
  14. - name: Set Backup Directory
  15. set_fact:
  16. etcd_backup_directory: "{{ etcd_backup_prefix }}/etcd-{{ ansible_date_time.date }}_{{ ansible_date_time.time }}"
  17. - name: Create Backup Directory
  18. file:
  19. path: "{{ etcd_backup_directory }}"
  20. state: directory
  21. owner: root
  22. group: root
  23. mode: 0600
  24. - name: Stat etcd v2 data directory
  25. stat:
  26. path: "{{ etcd_data_dir }}/member"
  27. register: etcd_data_dir_member
  28. - name: Backup etcd v2 data
  29. when: etcd_data_dir_member.stat.exists
  30. command: >-
  31. {{ bin_dir }}/etcdctl backup
  32. --data-dir {{ etcd_data_dir }}
  33. --backup-dir {{ etcd_backup_directory }}
  34. environment:
  35. ETCDCTL_API: 2
  36. retries: 3
  37. register: backup_v2_command
  38. until: backup_v2_command.rc == 0
  39. delay: "{{ retry_stagger | random + 3 }}"
  40. - name: Backup etcd v3 data
  41. command: >-
  42. {{ bin_dir }}/etcdctl
  43. --endpoints={{ etcd_access_addresses }}
  44. snapshot save {{ etcd_backup_directory }}/snapshot.db
  45. environment:
  46. ETCDCTL_API: 3
  47. ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  48. ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  49. retries: 3
  50. register: etcd_backup_v3_command
  51. until: etcd_backup_v3_command.rc == 0
  52. delay: "{{ retry_stagger | random + 3 }}"