来自 aws_rds 插件的端点 - Ansible
Endpoint from aws_rds plugin - Ansible
我正在使用 aws_rds 插件通过我的 rds cluster/instances 创建清单并根据环境标签创建 groups_vars。
plugin: aws_rds
regions:
- xx-xxxx-x
include_clusters: true
keyed_groups:
- key: tags.Environment
prefix: "tag_Environment_"
separator: ""
https://docs.ansible.com/ansible/2.9/plugins/inventory/aws_rds.html
问题是这个插件不允许使用端点名称所以我想知道是否可以在每个 group_var 创建时添加这个 cluster-xxxxxxxxxx.xx-xxxx-x.rds.amazonaws.com
的最后一部分,比如 ansible_host= ${ansible_host}.cluster-xxxxxxxxxx.xx-xxxx-x.rds.amazonaws.com
或类似的东西。
那些 AWS 清单插件正在从 API 收集大量信息,我最近对清单配置的 and here is how I proceeded to find the information I needed under the compose
参数有非常相似的要求。
为了获取我需要放在 compose
参数下的内容,我首先像您一样配置了库存。
然后我显示所有收集到的主机,使用
ansible-inventory --graph
这会产生类似
的结果
@all:
|--@nodes:
| |--node1
| |--node2
| |--node3
|--@ungrouped:
有了这个,我定位了一个节点,比方说 node1
,在这里,我显示了 Ansible 对它们的所有信息,做:
ansible -m setup node1
和
ansible -m debug -a "var=vars" node1
在所有这些中,搜索了所需的信息。
在您的情况下,可以通过以下方式实现:
ansible -m setup <one-of-the-hosts> | grep "cluster-" | grep ".rds.amazonaws.com"
和
ansible -m debug -a <one-of-the-hosts> | grep "cluster-" | grep ".rds.amazonaws.com"
最后但同样重要的是,配置了我在库存配置的compose
参数中找到的变量
compose:
ansible_host: <variable-name-found-at-step-4>
例如,在我的 EC2 配置中,它最终是 public_dns_address
plugin: aws_ec2
hostnames:
- tag:Name
# ^-- Given that you indeed have a tag named "Name" on your EC2 instances
compose:
ansible_host: public_dns_address
最后,我通过在groups_vars中定义这个变量实现了我想要的(所以我可以为每个环境定义一个)。
ansible_host: "{{ inventory_hostname }}.cluster-xxxxxxxx.xx-xxxx-x.rds.amazonaws.com"
我正在使用 aws_rds 插件通过我的 rds cluster/instances 创建清单并根据环境标签创建 groups_vars。
plugin: aws_rds
regions:
- xx-xxxx-x
include_clusters: true
keyed_groups:
- key: tags.Environment
prefix: "tag_Environment_"
separator: ""
https://docs.ansible.com/ansible/2.9/plugins/inventory/aws_rds.html
问题是这个插件不允许使用端点名称所以我想知道是否可以在每个 group_var 创建时添加这个 cluster-xxxxxxxxxx.xx-xxxx-x.rds.amazonaws.com
的最后一部分,比如 ansible_host= ${ansible_host}.cluster-xxxxxxxxxx.xx-xxxx-x.rds.amazonaws.com
或类似的东西。
那些 AWS 清单插件正在从 API 收集大量信息,我最近对清单配置的 compose
参数有非常相似的要求。
为了获取我需要放在
compose
参数下的内容,我首先像您一样配置了库存。然后我显示所有收集到的主机,使用
ansible-inventory --graph
这会产生类似
的结果@all: |--@nodes: | |--node1 | |--node2 | |--node3 |--@ungrouped:
有了这个,我定位了一个节点,比方说
node1
,在这里,我显示了 Ansible 对它们的所有信息,做:ansible -m setup node1
和
ansible -m debug -a "var=vars" node1
在所有这些中,搜索了所需的信息。
在您的情况下,可以通过以下方式实现:ansible -m setup <one-of-the-hosts> | grep "cluster-" | grep ".rds.amazonaws.com"
和
ansible -m debug -a <one-of-the-hosts> | grep "cluster-" | grep ".rds.amazonaws.com"
最后但同样重要的是,配置了我在库存配置的
compose
参数中找到的变量compose: ansible_host: <variable-name-found-at-step-4>
例如,在我的 EC2 配置中,它最终是
public_dns_address
plugin: aws_ec2 hostnames: - tag:Name # ^-- Given that you indeed have a tag named "Name" on your EC2 instances compose: ansible_host: public_dns_address
最后,我通过在groups_vars中定义这个变量实现了我想要的(所以我可以为每个环境定义一个)。
ansible_host: "{{ inventory_hostname }}.cluster-xxxxxxxx.xx-xxxx-x.rds.amazonaws.com"