【发布时间】:2019-09-11 15:07:38
【问题描述】:
我正在使用 Ansible pLaybook 对我的 AWS 上的所有实例进行扫描。我需要获取他们的私有 IP 并列出它们
我曾尝试使用 json 查询来过滤 Json 格式。格式输出是这样的......
ok: [localhost] => {
"msg": [
{
"private_dns_name": "ip-10.89.3.12.ec2.internal",
"private_ip_address": "10.89.3.12",
"public_dns_name": "",
"public_ip_address": null,
},
- hosts: localhost
connection: local
gather_facts: yes
tasks:
- name: Gather EC2 remote facts.
ec2_remote_facts:
region: "{{ region | default('us-east-1') }}"
filters:
instance-state-name: running
register: ec2_remote_facts
- set_fact:
msg: "{{ ec2_remote_facts | json_query('results[*].instances[*].private_ip_address') }} "
- debug: var=msg
我希望输出只是 private_IP 列表
【问题讨论】:
-
您是否必须仅使用“ec2_remote_facts”来收集有关 EC2 的数据?我问是因为现在不推荐使用此任务。您可以改用“ec2_instance_facts”
标签: amazon-ec2 ansible