|
1 | 1 | - name: Create daily snapshot |
2 | 2 | shell: "aws rds create-db-snapshot --db-snapshot-identifier '{{ rds_gfs_daily_snapshot_id }}' --db-instance-identifier '{{ rds_gfs_instance_id }}' --tags '{{ rds_gfs_daily_snapshot_tags | to_json }}' --region '{{ aws_region }}'" |
3 | 3 |
|
4 | | -- name: Wait until daily snapshot is created |
5 | | - shell: "aws rds wait db-snapshot-completed --db-snapshot-identifier '{{ rds_gfs_daily_snapshot_id }}' --region '{{ aws_region }}'" |
6 | | - |
7 | | -- name: Create weekly snapshot from the daily one |
8 | | - shell: "aws rds copy-db-snapshot --target-db-snapshot-identifier '{{ rds_gfs_weekly_snapshot_id }}' --source-db-snapshot-identifier '{{ rds_gfs_daily_snapshot_id }}' --tags '{{ rds_gfs_weekly_snapshot_tags | to_json }}' --region '{{ aws_region }}'" |
9 | | - when: ansible_date_time.weekday_number | int == rds_gfs_weekly_snapshot_weekday_nr |
10 | | - |
11 | | -- name: Create monthly snapshot from the daily one |
12 | | - shell: "aws rds copy-db-snapshot --target-db-snapshot-identifier '{{ rds_gfs_monthly_snapshot_id }}' --source-db-snapshot-identifier '{{ rds_gfs_daily_snapshot_id }}' --tags '{{ rds_gfs_monthly_snapshot_tags | to_json }}' --region '{{ aws_region }}'" |
13 | | - when: ansible_date_time.day | int == rds_gfs_monthly_snapshot_monthday_nr |
| 4 | +- name: Wait until daily cluster snapshot is created |
| 5 | + shell: "aws rds describe-db-snapshots --snapshot-type manual --db-snapshot-identifier '{{ rds_gfs_daily_snapshot_id }}' --region '{{ aws_region }}'" |
| 6 | + register: rds_gfs_daily_snapshot_status |
| 7 | + until: (rds_gfs_daily_snapshot_status.stdout | default({})|from_json).DBSnapshots[0].Status == "available" |
| 8 | + retries: 80 |
| 9 | + delay: 15 |
14 | 10 |
|
15 | 11 | - name: Get current snapshots |
16 | 12 | amazon.aws.rds_snapshot_info: |
|
21 | 17 |
|
22 | 18 | - debug: var=_rds_gfs_snapshots |
23 | 19 |
|
| 20 | +- name: Create weekly snapshot from the daily one |
| 21 | + when: ansible_date_time.weekday_number | int == rds_gfs_weekly_snapshot_weekday_nr |
| 22 | + block: |
| 23 | + - name: Copy snapshow |
| 24 | + shell: "aws rds copy-db-snapshot --target-db-snapshot-identifier '{{ rds_gfs_weekly_snapshot_id }}' --source-db-snapshot-identifier '{{ rds_gfs_daily_snapshot_id }}' --tags '{{ rds_gfs_weekly_snapshot_tags | to_json }}' --region '{{ aws_region }}'" |
| 25 | + - name: Wait until weekly snapshot is created |
| 26 | + shell: "aws rds describe-db-snapshots --db-snapshot-identifier '{{ rds_gfs_weekly_snapshot_id }}' --region '{{ aws_region }}'" |
| 27 | + register: rds_gfs_weekly_snapshot_status |
| 28 | + until: (rds_gfs_weekly_snapshot_status.stdout | default({})|from_json).DBSnapshots[0].Status == "available" |
| 29 | + retries: 60 |
| 30 | + delay: 15 |
| 31 | + |
| 32 | +- name: Create monthly snapshot from the daily one |
| 33 | + when: ansible_date_time.day | int == rds_gfs_monthly_snapshot_monthday_nr |
| 34 | + block: |
| 35 | + - name: Copy snapshot |
| 36 | + shell: "aws rds copy-db-snapshot --target-db-snapshot-identifier '{{ rds_gfs_monthly_snapshot_id }}' --source-db-snapshot-identifier '{{ rds_gfs_daily_snapshot_id }}' --tags '{{ rds_gfs_monthly_snapshot_tags | to_json }}' --region '{{ aws_region }}'" |
| 37 | + - name: Wait until monthly snapshot is created |
| 38 | + shell: "aws rds describe-db-snapshots --db-snapshot-identifier '{{ rds_gfs_monthly_snapshot_id }}' --region '{{ aws_region }}'" |
| 39 | + register: rds_gfs_monthly_snapshot_status |
| 40 | + until: (rds_gfs_monthly_snapshot_status.stdout | default({})|from_json).DBSnapshots[0].Status == "available" |
| 41 | + retries: 40 |
| 42 | + delay: 15 |
| 43 | + |
| 44 | + |
24 | 45 | - name: Get snapshots to be deleted |
25 | 46 | set_fact: |
26 | 47 | # Somehow I cannot get json_query to sort by creation time, every other attr works but not this |
|
0 commit comments