Ansible - 如何从寄存器访问调试输出?

Ansible - How to access debug output from register?

**您好。 请在下面帮助我。 我想访问“3.21.228.186”的 “public_ip”:“3.21.228.186”。 debug-var 变量应该是什么? ##########完整输出:

How can I solve this ?

> ok: [localhost] => {
> 
>     "start_AWS": {
> 
>         "changed": true,
> 
>         "failed": false,
> 
>         "instance_ids": [
> 
>             "i-12233ef3073q3622sad7baweq3445af406526"
> 
>         ],
> 
>         "instances": [
> 
>             {
> 
>                 "ami_launch_index": "0",
> 
>                 "architecture": "x86_64",
> 
>                 "block_device_mapping": {
> 
>                     "/dev/sda1": {
> 
>                         "delete_on_termination": true,
> 
>                         "status": "attached",
> 
>                         "volume_id": "vol-043ce7d3375a194d7"
> 
>                     }
> 
>                 },
> 
>                 "dns_name": "ec2-3-21-228-186.us-east-2.compute.amazonaws.com",
> 
>                 "ebs_optimized": false,
> 
>                 "groups": {
> 
>                     "sg-0d1460e84b87c3945": "launch-wizard-1"
> 
>                 },
> 
>                 "hypervisor": "xen",
> 
>                 "id": "i-0safdfsdf736gfd22sdfsdfsd7baaf406526",
> 
>                 "image_id": "ami-0a91cd140a1fc148a",
> 
>                 "instance_type": "t2.micro",
> 
>                 "kernel": null,
> 
>                 "key_name": "hem",
> 
>                 "launch_time": "2021-01-21T03:50:01.000Z",
> 
>                 "placement": "us-east-2b",
> 
>                 "private_dns_name": "ip-172-31-24-208.us-east-2.compute.internal",
> 
>                 "private_ip": "172.31.24.208",
> 
>                 "public_dns_name": "ec2-3-21-228-186.us-east-2.compute.amazonaws.com",
> 
>                 "public_ip": "3.21.228.186",
> 
>                 "ramdisk": null,
> 
>                 "region": "us-east-2",
> 
>                 "root_device_name": "/dev/sda1",
> 
>                 "root_device_type": "ebs",
> 
>                 "state": "running",
> 
>                 "state_code": 16,
> 
>                 "tags": {
> 
>                     "Name": "ubuntu"
> 
>                 },
> 
>                 "tenancy": "default",
> 
>                 "virtualization_type": "hvm"
> 
>             }
> 
>         ],
> 
>         "tagged_instances": []
> 
>     }
> 
> }

How can I solve this ? Thanks in advance


请帮忙。

我正在尝试获取此输出并将其作为另一个任务的输入

谢谢, 斯里维

以下请无视 错误的虚拟详细信息“看起来您的 post 主要是代码,请添加更多详细信息”

instances 是一个列表,您可以创建一个循环来打印每个 public_ip,如下所示:

- name: Print public ip
  debug:
    msg: "{{ item.public_ip }}"
  with_items: "{{ your_register_var.instances }}"

或者,如果您知道只有一个实例,请尝试以下操作

- name: Print public ip
  debug:
    msg: "{{ your_register_var.instances[0].public_ip }}"