變數查詢

  1. rescue 是在 block 執行出錯時才執行,判斷是否執行出錯,要先得知執行內容有哪些參數,使用 setup 模組過濾變數字串來查詢。例如:查詢主機 kvm11 的 ansible_lvm 相關參數如如下:
    [deyu1@kvm19 ansible]$ ansible -m setup -a "filter=ansible_lvm" kvm11
    kvm11 | SUCCESS => {
        "ansible_facts": {
            "ansible_lvm": {
                "lvs": {
                    "root": {
                        "size_g": "3.42",
                        "vg": "vg_kvm11"
                    },
                    "swap": {
                        "size_g": "0.12",
                        "vg": "vg_kvm11"
                    },
                    "test": {
                        "size_g": "0.10",
                        "vg": "fieldwork"
                    }
                },
                "pvs": {
                    "/dev/vda2": {
                        "free_g": "0.07",
                        "size_g": "3.61",
                        "vg": "vg_kvm11"
                    },
                    "/dev/vda3": {
                        "free_g": "0.09",
                        "size_g": "0.19",
                        "vg": "fieldwork"
                    }
                },
                "vgs": {
                    "fieldwork": {
                        "free_g": "0.09",
                        "num_lvs": "1",
                        "num_pvs": "1",
                        "size_g": "0.19"
                    },
                    "vg_kvm11": {
                        "free_g": "0.07",
                        "num_lvs": "2",
                        "num_pvs": "1",
                        "size_g": "3.61"
                    }
                }
            },
            "discovered_interpreter_python": "/usr/libexec/platform-python"
        },
        "changed": false
    }