如何使用 ansible 恢复 RDS aurora 快照
How do you restore an RDS aurora snapshot using ansibleR
我正在尝试使用 ansible 从快照创建 Aurora 数据库的克隆。我正在使用 rds_snapshot_facts 和 rds_instance 模块,因为 rds 模块不支持 Aurora。这是我的剧本(删除了 region/profile)。当我 运行 它失败并显示
Unable to restore DB instance from DB snapshot: An error occurred (DBSnapshotNotFound) when calling the RestoreDBInstanceFromDBSnapshot operation: DBSnapshot not found: snapshot id
有没有人设法使用 rds_instance 模块恢复像这样的快照,因为它的状态是预览我不确定它是否正常工作。
---
- hosts: localhost
connection: local
tasks:
- name: Get rds snapshots
rds_snapshot_facts:
db_cluster_identifier: "{{rds_live_instance}}"
register: rds_snapshot
- name: Create dev db
rds_instance:
wait: yes
vpc_security_group_ids:
- "{{rds_security_group}}"
storage_encrypted: yes
publicly_accessible: no
engine: aurora-mysql
db_subnet_group_name: default
id: "dev-{{branch}}"
cluster_id: "dev-{{branch}}-cluster"
creation_source: snapshot
availability_zone: eu-west-1a
auto_minor_version_upgrade: yes
allow_major_version_upgrade: no
db_snapshot_identifier: "{{item.db_cluster_snapshot_identifier}}"
snapshot_identifier: "{{item.db_cluster_snapshot_arn}}"
with_items:
- "{{rds_snapshot.cluster_snapshots | last }}"
不熟悉 Ansible,但查看您的错误,您似乎在调用 RestoreDBInstance*
api,它不适用于 Aurora 等基于集群的引擎。您应该调用 RestoreDBCluster*
版本,这将为您创建一个新集群。然后,您需要使用 CreateDbInstance
Api.
向集群添加一个实例
我将留给您解决如何在 Ansible 中进行连接的问题。希望这对您有所帮助!
在 Ansible 中我使用了 shell 模块 + AWS CLI
正在从快照恢复集群
- name: Restore Aurora DB cluster from snapshot
shell: |
aws rds restore-db-cluster-from-snapshot \
--db-cluster-identifier {{ aurora_cluster_name }} \
--snapshot-identifier {{ db_cluster_snapshot_arn }} \
--db-subnet-group-name {{ subnet_group_name }} \
--engine aurora-postgresql \
--region {{ region }}
已创建空集群。然后使用 rds_instance 模块
将实例添加到集群
- name: Add Aurora DB instance to cluster
rds_instance:
region: "{{ region }}"
engine: aurora-postgresql
db_instance_identifier: "{{ aurora_cluster_name }}-instance"
instance_type: db.t3.medium
cluster_id: "{{ aurora_cluster_name }}"
db_subnet_group_name: "{{ subnet_group_name }}"
wait: yes
不要忘记幂等性,先检查集群是否已经存在。
我正在尝试使用 ansible 从快照创建 Aurora 数据库的克隆。我正在使用 rds_snapshot_facts 和 rds_instance 模块,因为 rds 模块不支持 Aurora。这是我的剧本(删除了 region/profile)。当我 运行 它失败并显示
Unable to restore DB instance from DB snapshot: An error occurred (DBSnapshotNotFound) when calling the RestoreDBInstanceFromDBSnapshot operation: DBSnapshot not found: snapshot id
有没有人设法使用 rds_instance 模块恢复像这样的快照,因为它的状态是预览我不确定它是否正常工作。
---
- hosts: localhost
connection: local
tasks:
- name: Get rds snapshots
rds_snapshot_facts:
db_cluster_identifier: "{{rds_live_instance}}"
register: rds_snapshot
- name: Create dev db
rds_instance:
wait: yes
vpc_security_group_ids:
- "{{rds_security_group}}"
storage_encrypted: yes
publicly_accessible: no
engine: aurora-mysql
db_subnet_group_name: default
id: "dev-{{branch}}"
cluster_id: "dev-{{branch}}-cluster"
creation_source: snapshot
availability_zone: eu-west-1a
auto_minor_version_upgrade: yes
allow_major_version_upgrade: no
db_snapshot_identifier: "{{item.db_cluster_snapshot_identifier}}"
snapshot_identifier: "{{item.db_cluster_snapshot_arn}}"
with_items:
- "{{rds_snapshot.cluster_snapshots | last }}"
不熟悉 Ansible,但查看您的错误,您似乎在调用 RestoreDBInstance*
api,它不适用于 Aurora 等基于集群的引擎。您应该调用 RestoreDBCluster*
版本,这将为您创建一个新集群。然后,您需要使用 CreateDbInstance
Api.
我将留给您解决如何在 Ansible 中进行连接的问题。希望这对您有所帮助!
在 Ansible 中我使用了 shell 模块 + AWS CLI 正在从快照恢复集群
- name: Restore Aurora DB cluster from snapshot
shell: |
aws rds restore-db-cluster-from-snapshot \
--db-cluster-identifier {{ aurora_cluster_name }} \
--snapshot-identifier {{ db_cluster_snapshot_arn }} \
--db-subnet-group-name {{ subnet_group_name }} \
--engine aurora-postgresql \
--region {{ region }}
已创建空集群。然后使用 rds_instance 模块
将实例添加到集群- name: Add Aurora DB instance to cluster
rds_instance:
region: "{{ region }}"
engine: aurora-postgresql
db_instance_identifier: "{{ aurora_cluster_name }}-instance"
instance_type: db.t3.medium
cluster_id: "{{ aurora_cluster_name }}"
db_subnet_group_name: "{{ subnet_group_name }}"
wait: yes
不要忘记幂等性,先检查集群是否已经存在。