debug 輸出 magic 變數

  1. debug 模組列印變數 groups,內容由 inventory 設定取得。
    [deyu1@kvm19 ansible]$ ansible -m debug dev -a "var=groups"
    kvm11 | SUCCESS => {
        "groups": {
            "all": [
                "kvm11",
                "kvm12",
                "kvm15",
                "kvm13",
                "kvm14"
            ],
            "balancers": [
                "kvm15"
            ],
            "dev": [
                "kvm11"
            ],
            "prod": [
                "kvm13",
                "kvm14"
            ],
            "test": [
                "kvm12"
            ],
            "ungrouped": [],
            "webservers": [
                "kvm13",
                "kvm14"
            ]
        }
    }
    
  2. debug 模組列印變數 group_names,內容由 inventory 設定取得。
    [deyu1@kvm19 ansible]$ ansible -m debug all -a "var=group_names"
    kvm11 | SUCCESS => {
        "group_names": [
            "dev"
        ]
    }
    kvm12 | SUCCESS => {
        "group_names": [
            "test"
        ]
    }
    kvm15 | SUCCESS => {
        "group_names": [
            "balancers"
        ]
    }
    kvm13 | SUCCESS => {
        "group_names": [
            "prod",
            "webservers"
        ]
    }
    kvm14 | SUCCESS => {
        "group_names": [
            "prod",
            "webservers"
        ]
    }
    
  3. debug 模組列印變數 hostvars['kvm11']ansbile_facts 是空的,因為 debug 模組沒有執行 setup 模組。
    [deyu1@kvm19 ansible]$ ansible -m debug dev -a "var=hostvars['kvm11']"
    kvm11 | SUCCESS => {
        "hostvars['kvm11']": {
            "ansible_check_mode": false,
            "ansible_diff_mode": false,
            "ansible_facts": {},
            "ansible_forks": 5,
            "ansible_inventory_sources": [
                "/home/deyu1/ansible/inventory"
            ],
            "ansible_playbook_python": "/usr/libexec/platform-python",
            "ansible_ssh_host": "192.168.122.11",
            "ansible_verbosity": 0,
            "ansible_version": {
                "full": "2.8.5",
                "major": 2,
                "minor": 8,
                "revision": 5,
                "string": "2.8.5"
            },
            "group_names": [
                "dev"
            ],
            "groups": {
                "all": [
                    "kvm11",
                    "kvm12",
                    "kvm15",
                    "kvm13",
                    "kvm14"
                ],
                "balancers": [
                    "kvm15"
                ],
                "dev": [
                    "kvm11"
                ],
                "prod": [
                    "kvm13",
                    "kvm14"
                ],
                "test": [
                    "kvm12"
                ],
                "ungrouped": [],
                "webservers": [
                    "kvm13",
                    "kvm14"
                ]
            },
            "inventory_dir": "/home/deyu1/ansible",
            "inventory_file": "/home/deyu1/ansible/inventory",
            "inventory_hostname": "kvm11",
            "inventory_hostname_short": "kvm11",
            "omit": "__omit_place_holder__354579cf702a43d1da4b8c98248aa4acbce888dc",
            "playbook_dir": "/home/deyu1/ansible"
        }
    }