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.

54 lines
1.4 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. delay: "{{ retry_stagger | random + 3 }}"
  38. - name: Backup etcd v3 data
  39. command: >-
  40. {{ bin_dir }}/etcdctl
  41. --endpoints={{ etcd_access_addresses }}
  42. snapshot save {{ etcd_backup_directory }}/snapshot.db
  43. environment:
  44. ETCDCTL_API: 3
  45. ETCDCTL_CERT: "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}.pem"
  46. ETCDCTL_KEY: "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}-key.pem"
  47. retries: 3
  48. delay: "{{ retry_stagger | random + 3 }}"