我需要更新一些配置,其中包括我的集群中所有EC2节点的列表,但每个节点的配置也需要知道自己的EC2公共和私有IP地址。
完整……
使用 ec2_metadata_facts 在每个实例关联的变量中收集事实。 或者,如果你想使用 ec2_instance_facts 你会做的 lookup 基于 inventory_hostname :
ec2_instance_facts
lookup
inventory_hostname
样本游戏:
- name: gather ec2 facts per instance hosts: my_aws_instances gather_facts: no tasks: - ec2_metadata_facts: - name: debug debug: var=ansible_ec2_public_ipv4 - name: debug debug: var=ansible_ec2_local_ipv4