收集有關我們新例項的資訊
使用模組’Cloud’中的’os_server_facts’命令[ http://docs.ansible.com/ansible/os_server_module.html] 。變數在 ./group_vars/all 中定義,例項名稱在伺服器中:MyOwnPersonalInstance
。
$vi get_compute_info.yml
- name: Get and print instance IP
hosts: localhost
gather_facts: False
tasks:
- name: Get VM infos
os_server_facts:
auth:
auth_url: https://openstack-identity.mygroup/v2.0
username: "{{ AuthUserName }}"
password: "{{ AuthPassword }}"
project_name: "{{ TenantName }}"
validate_certs: False
server: "MyOwnPersonalInstance"
- name: Dump all
debug:
var: openstack_servers
$ansible-playbook -s get_compute_info.yml
[WARNING]: provided hosts list is empty, only localhost is available
PLAY [Get and print instance IP] ***********************************************
TASK [Get VM IP] ***************************************************************
ok: [localhost]
TASK [Affichage] ***************************************************************
ok: [localhost] => {
"openstack_servers": [
{
"OS-DCF:diskConfig": "MANUAL",
"OS-EXT-AZ:availability_zone": "fr",
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
[...]
"volumes": []
}
]
}
PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
這非常冗長。顯示大量資訊。通常只需要通過 SSH 訪問新例項的 IP 地址。