打印Ansible变量

时间:2018-10-30 22:35:34

标签: variables printing ansible

我正在尝试在运行Ansible剧本时打印特定的变量。

我要打印的信息是“主机名”和“软件版本”。我可以在使用debug选项后使用“-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
        }
    }

1 个答案:

答案 0 :(得分: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"
}

使用var的{​​{1}}选项,任务看起来像这样:

debug

并将其作为输出:

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