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

问题描述

**你好。 请帮助我在下面。 我想访问 '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": []
> 
>     }
> 
> }

我该如何解决这个问题?提前致谢


请帮忙。

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

谢谢, 斯里维

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

解决方法

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 }}"

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...