Páginas

Friday, 11 October 2019

Working with Jinja2 templates - II



Another way of using Jinja2 templates

{{ ansible_mounts | json_query("[?fstype == 'jfs2'].mount") | to_nice_yaml }}

We break it down:
 ansible_mounts : variable
json_query: filter to query a complex structure. ("[?fstype == 'jfs2'].mount") We select the file system type and show the mount fact
to_nice_yaml : give it some format, set it in yaml format

This is the information that we get when we run a playbook with that jinja template

- /
- /usr
- /var
- /tmp
- /home
- /admin
- /opt
- /var/adm/ras/livedump
- /usr/SE
- /usr/tws
- /home/metron
- /usr/SE/tools
- /usr/tws/TWS/stdlist


This is the whole information we get if we run the setup module and gather the information about ansible_mounts

ansible havut440 -m setup -a "filter=ansible_mounts"
havut440 | SUCCESS => {
    "ansible_facts": {
        "ansible_mounts": [
            {
                "block_available": 149827,
                "block_size": 4096,
                "block_total": 163840,
                "block_used": 14013,
                "device": "/dev/hd4",
                "fstype": "jfs2",
                "inode_available": 136867,
                "inode_total": 140635,
                "inode_used": 3768,
                "mount": "/",
                "options": "rw,log=/dev/hd8",
                "size_available": 613691392,
                "size_total": 671088640,
                "time": "Sep 06 11:03"
            },
            {
                "block_available": 241881,
                "block_size": 4096,
                "block_total": 1081344,
                "block_used": 839463,
                "device": "/dev/hd2",
                "fstype": "jfs2",
                "inode_available": 266615,
                "inode_total": 307293,
                "inode_used": 40678,
                "mount": "/usr",
                "options": "rw,log=/dev/hd8",
                "size_available": 990744576,
                "size_total": 4429185024,
                "time": "Sep 06 11:03"
            },
            {
                "block_available": 186123,
                "block_size": 4096,
                "block_total": 262144,
                "block_used": 76021,
                "device": "/dev/hd9var",
                "fstype": "jfs2",
                "inode_available": 167015,
                "inode_total": 175362,
                "inode_used": 8347,
                "mount": "/var",
                "options": "rw,log=/dev/hd8",
                "size_available": 762359808,
                "size_total": 1073741824,
                "time": "Sep 06 11:03"
            },
            {
                "block_available": 310047,
                "block_size": 4096,
                "block_total": 393216,
                "block_used": 83169,
                "device": "/dev/hd3",
                "fstype": "jfs2",
                "inode_available": 284868,
                "inode_total": 285485,
                "inode_used": 617,
                "mount": "/tmp",
                "options": "rw,nosuid,log=/dev/hd8",
                "size_available": 1269952512,
                "size_total": 1610612736,
                "time": "Sep 06 11:03"
            },
            {
                "block_available": 159061,
                "block_size": 4096,
                "block_total": 163840,
                "block_used": 4779,
                "device": "/dev/hd1",
                "fstype": "jfs2",
                "inode_available": 141501,
                "inode_total": 141771,
                "inode_used": 270,
                "mount": "/home",
                "options": "rw,nosuid,log=/dev/hd8",
                "size_available": 651513856,
                "size_total": 671088640,
                "time": "Sep 06 11:04"
            },
            {
                "block_available": 32673,
                "block_size": 4096,
                "block_total": 32768,
                "block_used": 95,
                "device": "/dev/hd11admin",
                "fstype": "jfs2",
                "inode_available": 29127,
                "inode_total": 29138,
                "inode_used": 11,
                "mount": "/admin",
                "options": "rw,log=/dev/hd8",
                "size_available": 133828608,
                "size_total": 134217728,
                "time": "Sep 06 11:04"
            },
            {
                "block_available": 0,
                "block_size": 1024,
                "block_total": -1,
                "block_used": -1,
                "device": "/proc",
                "fstype": "procfs",
                "inode_available": 0,
                "inode_total": 0,
                "inode_used": 0,
                "mount": "/proc",
                "options": "rw",
                "size_available": 0,
                "size_total": -1024,
                "time": "Sep 06 11:04"
            },
            {
                "block_available": 162074,
                "block_size": 4096,
                "block_total": 425984,
                "block_used": 263910,
                "device": "/dev/hd10opt",
                "fstype": "jfs2",
                "inode_available": 145670,
                "inode_total": 152065,
                "inode_used": 6395,
                "mount": "/opt",
                "options": "rw,log=/dev/hd8",
                "size_available": 663855104,
                "size_total": 1744830464,
                "time": "Sep 06 11:04"
            },
            {
                "block_available": 65444,
                "block_size": 4096,
                "block_total": 65536,
                "block_used": 92,
                "device": "/dev/livedump",
                "fstype": "jfs2",
                "inode_available": 58200,
                "inode_total": 58204,
                "inode_used": 4,
                "mount": "/var/adm/ras/livedump",
                "options": "rw,log=/dev/hd8",
                "size_available": 268058624,
                "size_total": 268435456,
                "time": "Sep 06 11:04"
            },
            {
                "block_available": 189364,
                "block_size": 4096,
                "block_total": 196608,
                "block_used": 7244,
                "device": "/dev/SElv",
                "fstype": "jfs2",
                "inode_available": 168419,
                "inode_total": 171683,
                "inode_used": 3264,
                "mount": "/usr/SE",
                "options": "rw,log=/dev/hd8",
                "size_available": 775634944,
                "size_total": 805306368,
                "time": "Sep 06 11:04"
            },
            {
                "block_available": 190030,
                "block_size": 4096,
                "block_total": 393216,
                "block_used": 203186,
                "device": "/dev/twslv",
                "fstype": "jfs2",
                "inode_available": 171564,
                "inode_total": 174867,
                "inode_used": 3303,
                "mount": "/usr/tws",
                "options": "rw,log=/dev/hd8",
                "size_available": 778362880,
                "size_total": 1610612736,
                "time": "Sep 06 11:04"
            },
            {
                "block_available": 91932,
                "block_size": 4096,
                "block_total": 98304,
                "block_used": 6372,
                "device": "/dev/metlv",
                "fstype": "jfs2",
                "inode_available": 82484,
                "inode_total": 87189,
                "inode_used": 4705,
                "mount": "/home/metron",
                "options": "rw,log=/dev/hd8",
                "size_available": 376553472,
                "size_total": 402653184,
                "time": "Sep 06 11:04"
            },
            {
                "block_available": 196466,
                "block_size": 4096,
                "block_total": 196608,
                "block_used": 142,
                "device": "/dev/SEtoolslv",
                "fstype": "jfs2",
                "inode_available": 174652,
                "inode_total": 174668,
                "inode_used": 16,
                "mount": "/usr/SE/tools",
                "options": "rw,log=/dev/hd8",
                "size_available": 804724736,
                "size_total": 805306368,
                "time": "Sep 06 11:04"
            },
            {
                "block_available": 226126,
                "block_size": 4096,
                "block_total": 262144,
                "block_used": 36018,
                "device": "/dev/twsstdlv",
                "fstype": "jfs2",
                "inode_available": 203925,
                "inode_total": 204264,
                "inode_used": 339,
                "mount": "/usr/tws/TWS/stdlist",
                "options": "rw,log=/dev/hd8",
                "size_available": 926212096,
                "size_total": 1073741824,
                "time": "Sep 06 11:04"
            }
        ],
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false
}

No comments:

Post a Comment