Promote command does not seem to work on the version of Ansible that I am using. So I am trying to create a new database as a replica of an existing one and after making it master, delete the source database.
I was trying to do it like this:
- Make replica
- Promote replica
- Delete source database
But now I am thinking of this:
- Create new database from source database last snapshot [as master from the beginning]
- Delete the source database
How would that playbook go?
My playbook:
- hosts: localhost
vars:
source_db_name: "{{ SOURCE_DB }}" # stagingdb
new_db_name: "{{ NEW_DB }}" # stagingdb2
tasks:
- name: Make RDS replica
local_action:
module: rds
region: us-east-1
command: replicate
instance_name : "{{ new_db_name }}"
source_instance: "{{ source_db_name }}"
wait: yes
wait_timeout: 900 # wait 15 minutes
# Notice - not working [Ansible bug]
- name: Promote RDS replica
local_action:
module: rds
region: us-east-1
command: promote
instance_name: "{{ new_db_name }}" # stagingdb2
backup_retention: 0
wait: yes
wait_timeout: 300
- name: Delete source db
local_action:
command: delete
instance_name: "{{ source_db_name }}"
region: us-east-1
You just need to use the
restore
command in the RDS module.Your playbook would then look something like:
There's a couple of extra tricks in there:
connection
tolocal
at the start of the play so, when combined withhosts: localhost
all of the tasks will be local tasks.YYYY-mm-dd-hh-mm
from the Ansible host's own facts (from gather_facts and it only targeting localhost). This is then used for the snapshot name to make sure that we create it (if one exists with the same name then Ansible won't create another snapshot - something that could be bad in this case as it would use an older snapshot before deleting your source database).instance_type
directly and remove the wholeget facts
task