-1

我试图在运行 Ansible playbook 时打印特定变量。

我要打印的信息是“主机名”和“软件版本”。使用调试选项后,我可以使用“-debug: var=output”打印输出,但是当我尝试打印特定变量“output.devices.hostname”时收到以下错误:“VARIABLE IS NOT DEFINED!” }

这是我的调试语句: - 调试:var=output.devices.hostname。这是整体调试输出。TIA 为您提供任何帮助。

            TASK [debug] ********************************************************************************************************
           ok: [bigIp-a] => {
        "output": {
            "changed": true,
            "devices": [
                {
                    "active_modules": [
                        "DNSSEC",
                        "Remote Desktop",
                        "External Interface and Network HSM, VE",
                        "DNS Rate Fallback, Unlimited",
                        "Firewall Checks",
                        "Max Compression, VE",
                        "Acceleration Manager, VE",
                        "Rate Shaping",
                        "Network Access",
                        "WOM, VE",
                        "DNS Express",
                        "SSL, Forward Proxy, VE",
                        "Base Endpoint Security Checks",
                        "Ram Cache",
                        "DNS Rate Limit, Unlimited QPS",
                        "Machine Certificate Checks",
                        "DNS Services (LAB)",
                        "Secure Virtual Keyboard",
                        "SDN Services, VE",
                        "Anti-Virus Checks",
                        "ASM, VE",
                        "STP",
                        "Advanced Protocols, VE",
                        "PSM, VE",
                        "APM, Web Application",
                        "AFM, VE (LAB ONLY - NO ROUTING)",
                        "App Tunnel",
                        "WBA, VE",
                        "DNS Licensed Objects, Unlimited",
                        "IPV6 Gateway",
                        "SSL, VE",
                        "AAM, Upgrade from WAM, (v11.4 & later)",
                        "Protected Workspace"
                    ],
                    "base_mac_address": "00:0c:29:41:92:07",
                    "build": "1.0.196",
                    "chassis_id": "564d22ff-08a0-b9a5-f4ccb7419207",
                    "chassis_type": "individual",
                    "configsync_address": "10.1.20.242",
                    "edition": "Hotfix HF1",
                    "failover_state": "active",
                    "full_path": "/Common/bigIp-b.min.local.lab",
                    "hostname": "bigIp-b.min.local.lab",
                    "management_address": "10.1.1.246",
                    "marketing_name": "BIG-IP Virtual Edition",
                    "multicast_address": "any",
                    "name": "bigIp-b.min.local.lab",
                    "optional_modules": [
                        "App Mode (TMSH Only, No Root/Bash)",
                        "BIG-IP VE, Multicast Routing",
                        "IPI Subscription, 1Yr, VE",
                        "IPI Subscription, 3Yr, VE",
                        "PEM URL Filtering, Subscription, 1Yr, 200Mbps",
                        "PEM URL Filtering, Subscription, 3Yr, 200Mbps",
                        "PEM, Quota Management, VE",
                        "PEM, VE",
                        "Routing Bundle, VE",
                        "SWG Subscription, 1Yr, VE",
                        "SWG Subscription, 3Yr, VE",
                        "URL Filtering Subscription, 1Yr, VE",
                        "URL Filtering Subscription, 3Yr, VE"
                    ],
                    "platform_id": "Z100",
                    "primary_mirror_address": "10.1.20.242",
                    "product": "BIG-IP",
                    "self": "no",
                    "software_version": "12.1.1",
                    "timezone": "America/Chicago",
                    "unicast_addresses": [
                        {
                            "effective_ip": "10.1.20.242",
                            "effective_port": 1026,
                            "ip": "10.1.20.242",
                            "port": 1026
                        },
                        {
                            "effective_ip": "management-ip",
                            "effective_port": 1026,
                            "ip": "management-ip",
                            "port": 1026
                        }
                    ]
                },
                {
                    "active_modules": [
                        "DNSSEC",
                        "Remote Desktop",
                        "External Interface and Network HSM, VE",
                        "DNS Rate Fallback, Unlimited",
                        "Firewall Checks",
                        "Max Compression, VE",
                        "Acceleration Manager, VE",
                        "Rate Shaping",
                        "Network Access",
                        "WOM, VE",
                        "DNS Express",
                        "SSL, Forward Proxy, VE",
                        "Base Endpoint Security Checks",
                        "Ram Cache",
                        "DNS Rate Limit, Unlimited QPS",
                        "Machine Certificate Checks",
                        "DNS Services (LAB)",
                        "Secure Virtual Keyboard",
                        "SDN Services, VE",
                        "Anti-Virus Checks",
                        "ASM, VE",
                        "STP",
                        "Advanced Protocols, VE",
                        "PSM, VE",
                        "APM, Web Application",
                        "AFM, VE (LAB ONLY - NO ROUTING)",
                        "App Tunnel",
                        "WBA, VE",
                        "DNS Licensed Objects, Unlimited",
                        "IPV6 Gateway",
                        "SSL, VE",
                        "AAM, Upgrade from WAM, (v11.4 & later)",
                        "Protected Workspace"
                    ],
                    "base_mac_address": "00:0c:29:31:fc:47",
                    "build": "1.0.196",
                    "chassis_id": "564de91e-b7c1-bda0-1bec5e31fc47",
                    "chassis_type": "individual",
                    "configsync_address": "10.1.20.241",
                    "edition": "Hotfix HF1",
                    "failover_state": "standby",
                    "full_path": "/Common/bigip-a.min.local.lab",
                    "hostname": "bigIp-a.min.local.lab",
                    "management_address": "10.1.1.245",
                    "marketing_name": "BIG-IP Virtual Edition",
                    "multicast_address": "any",
                    "name": "bigip-a.min.local.lab",
                    "optional_modules": [
                        "App Mode (TMSH Only, No Root/Bash)",
                        "BIG-IP VE, Multicast Routing",
                        "IPI Subscription, 1Yr, VE",
                        "IPI Subscription, 3Yr, VE",
                        "PEM URL Filtering, Subscription, 1Yr, 200Mbps",
                        "PEM URL Filtering, Subscription, 3Yr, 200Mbps",
                        "PEM, Quota Management, VE",
                        "PEM, VE",
                        "Routing Bundle, VE",
                        "SWG Subscription, 1Yr, VE",
                        "SWG Subscription, 3Yr, VE",
                        "URL Filtering Subscription, 1Yr, VE",
                        "URL Filtering Subscription, 3Yr, VE"
                    ],
                    "platform_id": "Z100",
                    "primary_mirror_address": "10.1.20.241",
                    "product": "BIG-IP",
                    "self": "yes",
                    "software_version": "12.1.1",
                    "timezone": "America/Chicago",
                    "unicast_addresses": [
                        {
                            "effective_ip": "10.1.20.241",
                            "effective_port": 1026,
                            "ip": "10.1.20.241",
                            "port": 1026
                        },
                        {
                            "effective_ip": "management-ip",
                            "effective_port": 1026,
                            "ip": "management-ip",
                            "port": 1026
                        }
                    ]
                }
            ],
            "failed": false
        }
    }
            ok: [bigIp-b] => {
        "output": {
            "changed": true,
            "devices": [
                {
                    "active_modules": [
                        "DNSSEC",
                        "Remote Desktop",
                        "External Interface and Network HSM, VE",
                        "DNS Rate Fallback, Unlimited",
                        "Firewall Checks",
                        "Max Compression, VE",
                        "Acceleration Manager, VE",
                        "Rate Shaping",
                        "Network Access",
                        "WOM, VE",
                        "DNS Express",
                        "SSL, Forward Proxy, VE",
                        "Base Endpoint Security Checks",
                        "Ram Cache",
                        "DNS Rate Limit, Unlimited QPS",
                        "Machine Certificate Checks",
                        "DNS Services (LAB)",
                        "Secure Virtual Keyboard",
                        "SDN Services, VE",
                        "Anti-Virus Checks",
                        "ASM, VE",
                        "STP",
                        "Advanced Protocols, VE",
                        "PSM, VE",
                        "APM, Web Application",
                        "AFM, VE (LAB ONLY - NO ROUTING)",
                        "App Tunnel",
                        "WBA, VE",
                        "DNS Licensed Objects, Unlimited",
                        "IPV6 Gateway",
                        "SSL, VE",
                        "AAM, Upgrade from WAM, (v11.4 & later)",
                        "Protected Workspace"
                    ],
                    "base_mac_address": "00:0c:29:41:92:07",
                    "build": "1.0.196",
                    "chassis_id": "564d22ff-08a0-b9a5-f4ccb7419207",
                    "chassis_type": "individual",
                    "configsync_address": "10.1.20.242",
                    "edition": "Hotfix HF1",
                    "failover_state": "active",
                    "full_path": "/Common/bigIp-b.min.local.lab",
                    "hostname": "bigIp-b.min.local.lab",
                    "management_address": "10.1.1.246",
                    "marketing_name": "BIG-IP Virtual Edition",
                    "multicast_address": "any",
                    "name": "bigIp-b.min.local.lab",
                    "optional_modules": [
                        "App Mode (TMSH Only, No Root/Bash)",
                        "BIG-IP VE, Multicast Routing",
                        "IPI Subscription, 1Yr, VE",
                        "IPI Subscription, 3Yr, VE",
                        "PEM URL Filtering, Subscription, 1Yr, 200Mbps",
                        "PEM URL Filtering, Subscription, 3Yr, 200Mbps",
                        "PEM, Quota Management, VE",
                        "PEM, VE",
                        "Routing Bundle, VE",
                        "SWG Subscription, 1Yr, VE",
                        "SWG Subscription, 3Yr, VE",
                        "URL Filtering Subscription, 1Yr, VE",
                        "URL Filtering Subscription, 3Yr, VE"
                    ],
                    "platform_id": "Z100",
                    "primary_mirror_address": "10.1.20.242",
                    "product": "BIG-IP",
                    "self": "yes",
                    "software_version": "12.1.1",
                    "timezone": "America/Chicago",
                    "unicast_addresses": [
                        {
                            "effective_ip": "10.1.20.242",
                            "effective_port": 1026,
                            "ip": "10.1.20.242",
                            "port": 1026
                        },
                        {
                            "effective_ip": "management-ip",
                            "effective_port": 1026,
                            "ip": "management-ip",
                            "port": 1026
                        }
                    ]
                },
                {
                    "active_modules": [
                        "DNSSEC",
                        "Remote Desktop",
                        "External Interface and Network HSM, VE",
                        "DNS Rate Fallback, Unlimited",
                        "Firewall Checks",
                        "Max Compression, VE",
                        "Acceleration Manager, VE",
                        "Rate Shaping",
                        "Network Access",
                        "WOM, VE",
                        "DNS Express",
                        "SSL, Forward Proxy, VE",
                        "Base Endpoint Security Checks",
                        "Ram Cache",
                        "DNS Rate Limit, Unlimited QPS",
                        "Machine Certificate Checks",
                        "DNS Services (LAB)",
                        "Secure Virtual Keyboard",
                        "SDN Services, VE",
                        "Anti-Virus Checks",
                        "ASM, VE",
                        "STP",
                        "Advanced Protocols, VE",
                        "PSM, VE",
                        "APM, Web Application",
                        "AFM, VE (LAB ONLY - NO ROUTING)",
                        "App Tunnel",
                        "WBA, VE",
                        "DNS Licensed Objects, Unlimited",
                        "IPV6 Gateway",
                        "SSL, VE",
                        "AAM, Upgrade from WAM, (v11.4 & later)",
                        "Protected Workspace"
                    ],
                    "base_mac_address": "00:0c:29:31:fc:47",
                    "build": "1.0.196",
                    "chassis_id": "564de91e-b7c1-bda0-1bec5e31fc47",
                    "chassis_type": "individual",
                    "configsync_address": "10.1.20.241",
                    "edition": "Hotfix HF1",
                    "failover_state": "standby",
                    "full_path": "/Common/bigip-a.min.local.lab",
                    "hostname": "BIG-IP-6A.Yellow.Lab",
                    "management_address": "10.1.1.245",
                    "marketing_name": "BIG-IP Virtual Edition",
                    "multicast_address": "any",
                    "name": "bigip-a.min.local.lab",
                    "optional_modules": [
                        "App Mode (TMSH Only, No Root/Bash)",
                        "BIG-IP VE, Multicast Routing",
                        "IPI Subscription, 1Yr, VE",
                        "IPI Subscription, 3Yr, VE",
                        "PEM URL Filtering, Subscription, 1Yr, 200Mbps",
                        "PEM URL Filtering, Subscription, 3Yr, 200Mbps",
                        "PEM, Quota Management, VE",
                        "PEM, VE",
                        "Routing Bundle, VE",
                        "SWG Subscription, 1Yr, VE",
                        "SWG Subscription, 3Yr, VE",
                        "URL Filtering Subscription, 1Yr, VE",
                        "URL Filtering Subscription, 3Yr, VE"
                    ],
                    "platform_id": "Z100",
                    "primary_mirror_address": "10.1.20.241",
                    "product": "BIG-IP",
                    "self": "no",
                    "software_version": "12.1.1",
                    "timezone": "America/Chicago",
                    "unicast_addresses": [
                        {
                            "effective_ip": "10.1.20.241",
                            "effective_port": 1026,
                            "ip": "10.1.20.241",
                            "port": 1026
                        },
                        {
                            "effective_ip": "management-ip",
                            "effective_port": 1026,
                            "ip": "management-ip",
                            "port": 1026
                        }
                    ]
                }
            ],
            "failed": false
        }
    }
4

1 回答 1

0

从我们在评论中的讨论来看,这部剧应该会告诉你你想要什么:

  - debug:
      msg: "{{ item.hostname }}"
    with_items: "{{ output.devices }}"

我得到以下信息:

TASK [debug] ************************************************************************************************************************
ok: [localhost] => (item=None) => {
    "msg": "bigIp-b.min.local.lab"
}
ok: [localhost] => (item=None) => {
    "msg": "BIG-IP-6A.Yellow.Lab"
}

使用varto 选项debug,任务如下所示:

  - debug:
      var: item.hostname 
    with_items: "{{ output.devices }}"

并将其作为输出:

TASK [debug] ************************************************************************************************************************
ok: [localhost] => (item=None) => {
    "item.hostname": "bigIp-b.min.local.lab"
}
ok: [localhost] => (item=None) => {
    "item.hostname": "BIG-IP-6A.Yellow.Lab"
}
于 2018-10-31T15:44:59.927 回答