我正在尝试使用ansible从快照创建Aurora数据库的克隆。我正在使用rds_snapshot_facts和rds_instance模块,因为rds模块不支持Aurora。这是我的剧本(删除了区域/配置文件)。当我运行它失败
无法从数据库快照还原数据库实例:调用RestoreDBInstanceFromDBSnapshot操作时发生错误(DBSnapshotNotFound):未找到DBSnapshot:快照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 }}"
答案 0 :(得分:1)
在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
别忘了幂等性,请先检查集群是否已存在。
答案 1 :(得分:0)
不熟悉Ansible,但是看着您的错误,您似乎正在调用RestoreDBInstance*
API,该API无法与基于集群的引擎(如Aurora)一起使用。您应该调用RestoreDBCluster*
版本,这将为您创建一个新的群集。然后,您需要使用CreateDbInstance
Api将实例添加到集群。
我将留给您了解如何在Ansible中进行连接。希望这会有所帮助!