Печать Ansible Variables - PullRequest
       3

Печать Ansible Variables

0 голосов
/ 31 октября 2018

Я пытаюсь напечатать определенные переменные во время запуска Ansible playbook.

Информация, которую я ищу для печати, - это «имя хоста» и «версия программного обеспечения». Я могу напечатать вывод после использования опции отладки, используя «- debug: var = output», но я получил следующую ошибку при попытке напечатать определенные переменные «output.devices.hostname»: «VARIABLE НЕ ОПРЕДЕЛЕНО!» }

Вот мой оператор отладки: - debug: 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 голосов
/ 31 октября 2018

Из нашего обсуждения в комментариях, эта игра должна показать вам, что вы хотите:

  - 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 для 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"
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...