如何基于aws ec2目录主机名访问ansible playbook中的主机名标签';s的ip地址?
我正在ansible 2.9中使用aws ec2插件。我想用专用ip地址连接到aws ec2实例,但在我的剧本中,我想显示其他主机名标记,如主机名和区域以及相应的专用ip地址。关于如何在剧本中实现这一点,有什么建议吗 这是我的ec2清单: testall.aws_ec2.yml如何基于aws ec2目录主机名访问ansible playbook中的主机名标签';s的ip地址?,ansible,ansible-2.x,ansible-inventory,Ansible,Ansible 2.x,Ansible Inventory,我正在ansible 2.9中使用aws ec2插件。我想用专用ip地址连接到aws ec2实例,但在我的剧本中,我想显示其他主机名标记,如主机名和区域以及相应的专用ip地址。关于如何在剧本中实现这一点,有什么建议吗 这是我的ec2清单: testall.aws_ec2.yml plugin: aws_ec2 hostnames: - tag:Name - tag: Region - private-ip-address compose: ansi
plugin: aws_ec2
hostnames:
- tag:Name
- tag: Region
- private-ip-address
compose:
ansible_host: private_ip_address
以下是我的剧本:
test-playbook.yml
---
- hosts: "{{ variable_host | default('test')}}"
remote_user: ubuntu
become: yes
become_method: sudo
tasks:
- debug:
msg: "{{ inventory_hostname }}"
...
我的剧本如下:
ansible-playbook -i testall.aws_ec2.yml test-playbook.yml --extra-vars variable_host=testall
但是,我的playbook只返回tag:Name(清单中主机名中指定的第一项):
第一个匹配项用于
inventory\u hostname
,其中hostnames
arg的值是按优先级降序排列的列表
从ansible doc--键入inventory amazon.aws.aws_ec2
:
hostnames:
description:
- A list in order of precedence for hostname variables.
- You can use the options specified in U(http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html#options).
- To use tags as hostnames use the syntax tag:Name=Value to use the hostname Name_Value, or tag:Name to use the value of the Name tag.
type: list
default: []
您可以使用模块ec2\u metadata\u facts
找到每个清单主机的
ansible doc amazon.aws.ec2\u metadata\u facts
这是事实收集,您至少应该从调试或错误中得到一些信息。然后应该以重述结束。请向我们展示您的剧本的全部结果。非常感谢-这很有帮助!
hostnames:
description:
- A list in order of precedence for hostname variables.
- You can use the options specified in U(http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html#options).
- To use tags as hostnames use the syntax tag:Name=Value to use the hostname Name_Value, or tag:Name to use the value of the Name tag.
type: list
default: []