2018-08-31 04:17:02 +02:00
|
|
|
---
|
|
|
|
- block:
|
|
|
|
|
|
|
|
- name: set the two regions for the source DB and the replica
|
|
|
|
set_fact:
|
|
|
|
region_src: "{{ aws_region }}"
|
2019-06-25 15:54:03 +02:00
|
|
|
region_dest: "{{ aws_region }}"
|
2018-08-31 04:17:02 +02:00
|
|
|
|
|
|
|
- name: set up aws connection info
|
|
|
|
set_fact:
|
|
|
|
aws_connection_info: &aws_connection_info
|
|
|
|
aws_access_key: "{{ aws_access_key }}"
|
|
|
|
aws_secret_key: "{{ aws_secret_key }}"
|
|
|
|
security_token: "{{ security_token }}"
|
|
|
|
no_log: yes
|
|
|
|
|
|
|
|
- name: Ensure the resource doesn't exist
|
|
|
|
rds_instance:
|
|
|
|
id: "{{ instance_id }}"
|
|
|
|
state: absent
|
|
|
|
skip_final_snapshot: True
|
|
|
|
region: "{{ region_src }}"
|
|
|
|
<<: *aws_connection_info
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- not result.changed
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- name: Create a source DB instance
|
|
|
|
rds_instance:
|
|
|
|
id: "{{ instance_id }}"
|
|
|
|
state: present
|
|
|
|
engine: mysql
|
|
|
|
backup_retention_period: 1
|
|
|
|
username: "{{ username }}"
|
|
|
|
password: "{{ password }}"
|
|
|
|
db_instance_class: "{{ db_instance_class }}"
|
|
|
|
allocated_storage: "{{ allocated_storage }}"
|
|
|
|
region: "{{ region_src }}"
|
|
|
|
<<: *aws_connection_info
|
|
|
|
register: source_db
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- source_db.changed
|
|
|
|
- "source_db.db_instance_identifier == '{{ instance_id }}'"
|
|
|
|
|
|
|
|
- name: Create a read replica in a different region
|
|
|
|
rds_instance:
|
|
|
|
id: "{{ instance_id }}-replica"
|
|
|
|
state: present
|
2019-07-25 15:49:08 +02:00
|
|
|
source_db_instance_identifier: "{{ instance_id }}"
|
2018-08-31 04:17:02 +02:00
|
|
|
engine: mysql
|
|
|
|
username: "{{ username }}"
|
|
|
|
password: "{{ password }}"
|
|
|
|
read_replica: True
|
|
|
|
db_instance_class: "{{ db_instance_class }}"
|
|
|
|
allocated_storage: "{{ allocated_storage }}"
|
|
|
|
region: "{{ region_dest }}"
|
|
|
|
<<: *aws_connection_info
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Test idempotence with a read replica
|
|
|
|
rds_instance:
|
|
|
|
id: "{{ instance_id }}-replica"
|
|
|
|
state: present
|
2019-07-25 15:49:08 +02:00
|
|
|
source_db_instance_identifier: "{{ instance_id }}"
|
2018-08-31 04:17:02 +02:00
|
|
|
engine: mysql
|
|
|
|
username: "{{ username }}"
|
|
|
|
password: "{{ password }}"
|
|
|
|
db_instance_class: "{{ db_instance_class }}"
|
|
|
|
allocated_storage: "{{ allocated_storage }}"
|
|
|
|
region: "{{ region_dest }}"
|
|
|
|
<<: *aws_connection_info
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- not result.changed
|
|
|
|
|
|
|
|
- name: Test idempotence with read_replica=True
|
|
|
|
rds_instance:
|
|
|
|
id: "{{ instance_id }}-replica"
|
|
|
|
state: present
|
|
|
|
read_replica: True
|
2019-07-25 15:49:08 +02:00
|
|
|
source_db_instance_identifier: "{{ instance_id }}"
|
2018-08-31 04:17:02 +02:00
|
|
|
engine: mysql
|
|
|
|
username: "{{ username }}"
|
|
|
|
password: "{{ password }}"
|
|
|
|
db_instance_class: "{{ db_instance_class }}"
|
|
|
|
allocated_storage: "{{ allocated_storage }}"
|
|
|
|
region: "{{ region_dest }}"
|
|
|
|
<<: *aws_connection_info
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Promote the read replica
|
|
|
|
rds_instance:
|
|
|
|
id: "{{ instance_id }}-replica"
|
|
|
|
state: present
|
|
|
|
read_replica: False
|
|
|
|
region: "{{ region_dest }}"
|
|
|
|
<<: *aws_connection_info
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result.changed
|
|
|
|
|
|
|
|
- name: Test idempotence
|
|
|
|
rds_instance:
|
|
|
|
id: "{{ instance_id }}-replica"
|
|
|
|
state: present
|
|
|
|
read_replica: False
|
|
|
|
region: "{{ region_dest }}"
|
|
|
|
<<: *aws_connection_info
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- not result.changed
|
|
|
|
|
|
|
|
always:
|
|
|
|
|
|
|
|
- name: Remove the DB instance
|
|
|
|
rds_instance:
|
|
|
|
id: "{{ instance_id }}"
|
|
|
|
state: absent
|
|
|
|
skip_final_snapshot: True
|
|
|
|
region: "{{ region_src }}"
|
|
|
|
<<: *aws_connection_info
|
2019-07-25 15:49:08 +02:00
|
|
|
ignore_errors: yes
|
2018-08-31 04:17:02 +02:00
|
|
|
|
|
|
|
- name: Remove the DB replica
|
|
|
|
rds_instance:
|
|
|
|
id: "{{ instance_id }}-replica"
|
|
|
|
state: absent
|
|
|
|
skip_final_snapshot: True
|
|
|
|
region: "{{ region_dest }}"
|
|
|
|
<<: *aws_connection_info
|
2019-07-25 15:49:08 +02:00
|
|
|
ignore_errors: yes
|