Páginas

Wednesday, 21 April 2021

Accesing registered nested variables

 You can get to registered nested variables by using jinja filters.

Register the output of a variable and then use Jinja filters to get to the attribute you want to show


 - debug:

       var: zabbix_host.hosts | map(attribute='parentTemplates') | flatten | map(attribute='name')



Before applying Jinja filters

TASK [debug] ************************************************************************************

ok: [localhost] => {

    "zabbix_host.hosts": [

        {

            "auto_compress": "1",

            "available": "1",

            "description": "",

            "disable_until": "0",

            "discover": "0",

            "error": "",

            "errors_from": "0",

            "flags": "0",

            "maintenance_from": "0",

            "maintenance_status": "0",

            "maintenance_type": "0",

            "maintenanceid": "0",

            "name": "db0061",

            "parentTemplates": [

                {

                    "name": "Template OS Linux",

                    "templateid": "10001"

                },

                {

                    "name": "EMA_Comprobacion_WEB",

                    "templateid": "11637"

                }

            ],


After applying Jinja filters

TASK [debug] *******************************************************************
ok: [localhost] => {
    "zabbix_host.hosts | map(attribute='parentTemplates') | flatten | map(attribute='name')": [
        "Template OS Linux",
        "EMA_Comprobacion_WEB"
    ]
}