ansible Using Ansible with OpenStack Gather informations about our new instance


Use the 'os_server_facts' command from module 'Cloud' []. Variables are defined in ./group_vars/all and the instance name is in server: "MyOwnPersonalInstance".

$vi get_compute_info.yml
- name: Get and print instance IP
  hosts: localhost
  gather_facts: False
  - name: Get VM infos
        auth_url: https://openstack-identity.mygroup/v2.0
        username: "{{ AuthUserName }}"
        password: "{{ AuthPassword }}"
        project_name: "{{ TenantName }}"
      validate_certs: False
      server: "MyOwnPersonalInstance"

  - name: Dump all
      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

This is very verbose. Lots of information is displayed. Usually only the IP address is needed to access the new instance via SSH.