使用 Ansible 获取 AWS RDS Aurora 集群端点

Get AWS RDS Aurora cluster endpoint using Ansible

我需要能够通过提供集群的“数据库标识符”来获取使用 Ansible 的现有 AWS RDS Aurora 集群的 cluster endpoint

在我的剧本中使用 community.aws.rds_instance_info 并引用编写器实例的数据库实例标识符时:

---

- name: Test
  hosts: localhost
  connection: local
  tasks:
    - name: Get RDS Aurora cluster
      community.aws.rds_instance_info:
        db_instance_identifier: "test-cluster-1" # the writer instance of the aurora db cluster
      register: rds_aurora_cluster

它 return 是预期的实例。

但如果我使用集群端点 (test-cluster),它不会 return 任何实例或任何集群级信息:

ok: [localhost] => {
    "changed": false,
    "instances": [],
    "invocation": {
        "module_args": {
            "aws_access_key": "<omitted>",
            "aws_ca_bundle": null,
            "aws_config": null,
            "aws_secret_key": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "db_instance_identifier": "test-cluster",
            "debug_botocore_endpoint_logs": false,
            "ec2_url": null,
            "filters": null,
            "profile": null,
            "region": "us-east-1",
            "security_token": null,
            "validate_certs": true
        }
    }
}

我也试过在 amazon.aws.rds collection 中使用 amazon.aws.aws_rds 模块,它有一个 include_clusters 参数:

---

- name: Test
  hosts: localhost
  connection: local
  vars:
  collections:
    - amazon.aws
  tasks:
    - name: Get RDS Aurora cluster
      aws_rds:
        db_instance_identifier: "test-cluster"
        include_clusters: true
      register: rds_aurora_cluster

当我 运行 我得到那个剧本时:

ERROR! couldn't resolve module/action 'aws_rds'. This often indicates a misspelling, missing collection, or incorrect module path.
The error appears to be in '/Users/username/Desktop/test/test.yml': line 23, column 7, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
    - name: Get RDS Aurora cluster
      ^ here

我已经确认安装了最新版本的合集:

❯ ansible-galaxy collection list
# /usr/local/Cellar/ansible/4.4.0/libexec/lib/python3.9/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    2.0.0

并且我已经验证了包裹:

❯ ansible-galaxy collection verify amazon.aws
Downloading https://galaxy.ansible.com/download/amazon-aws-2.0.0.tar.gz to /Users/username/.ansible/tmp/ansible-local-8367rrxw073b/tmpejakna6g/amazon-aws-2.0.0-_y4d1bqj
Verifying 'amazon.aws:2.0.0'.
Installed collection found at '/usr/local/Cellar/ansible/4.4.0/libexec/lib/python3.9/site-packages/ansible_collections/amazon/aws'
MANIFEST.json hash: 1286503f7bcc6dd26aecf9bec4d055e8f0d2e355522f97b620522a5aa754cb9e
Successfully verified that checksums for 'amazon.aws:2.0.0' match the remote collection.

I've also tried using the amazon.aws.aws_rds module in the amazon.aws.rds collection, which has an include_clusters parameter:

人们将从您链接到的文档中观察到 aws_rds 是一个 库存插件 而不是 模块 ;不幸的是,他们在顶部有一个复制粘贴错误,声称可以在剧本中使用它,但是 the examples section 通过将该 yaml 放在名为 WHATEVER.aws_rds.yaml 的文件中然后确认选择 运行 ansible-inventory -i ./WHATEVER.aws_rds.yaml --list

仅基于 grep -r 的一些使用,库存插件或 command: aws rds describe-db-clusters ... 似乎是仅有的两个提供极光感知机制


工作示例:

test.aws_rds.yml 库存文件:

plugin: aws_rds
regions:
  - us-east-1
include_clusters: true

test.yml 剧本,用 ansible-playbook test.yml -i ./test.aws_rds.yml:

执行
---

- name: Test
  hosts: localhost
  connection: local
  tasks:
    - name: test
      ansible.builtin.shell:
        cmd: echo {{ hostvars['test-cluster'].endpoint }}