2016-04-11 48 views
1
--- 
- name: "Gateway Checker" 
    hosts: vms_windows 
    gather_facts: True 
    tasks: 
    - debug: var=ansible_interfaces 

使用獲取我:找回Windows主機的默認網關使用PowerShell腳本

TASK [debug]  ******************************************************************* 
ok: [dc00.domain.test] => { 
    "ansible_interfaces": [ 
     { 
      "default_gateway": "192.168.10.254", 
      "dns_domain": null, 
      "interface_index": 12, 
      "interface_name": "Intel(R) PRO/1000 MT Network Connection" 
     } 
    ] 
} 

但去爲:

- debug: var=ansible_interfaces.default_gateway 

獲取我:

"ansible_interfaces.default_gateway": "VARIABLE IS NOT DEFINED!" 

任何想法上我可能在這裏做錯了什麼?

回答

0

那麼,你可能會在這種情況下使用以下格式:

- debug: var=ansible_interfaces[0].default_gateway 

- debug: var=ansible_interfaces.0.default_gateway 

請,要請你注意,這是陣列接口,該代碼會,如果你正常工作只有一個接口。但是一般情況下,如果你的接口很少,默認網關可以在其他接口中,並且你應該在這種情況下遍歷數組。

相關問題