# Create dynamic inventory for OpenStack

**URL:** <https://forum.ansible.com/t/create-dynamic-inventory-for-openstack/25398>\
**Category:** Ansible Project\
**Created:** [September 2, 2017, 11:04am UTC](https://forum.ansible.com/t/create-dynamic-inventory-for-openstack/25398 "2017-09-02T11:04:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soufiane\_Benmalek](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@Soufiane\_Benmalek](https://forum.ansible.com/u/Soufiane_Benmalek)\
**Post date:** [September 2, 2017, 11:04am UTC](https://forum.ansible.com/t/create-dynamic-inventory-for-openstack/25398/1 "2017-09-02T11:04:17Z")

</div>

Hi,

I use Ansible to create servers on OpenStack and to install mysql on it.  
All is done once, so in my code I want to register the public IP of the new server and store it in my Ansible hosts file. But it does not seem to work:

- name: launch an instance  
os\_server:  
state: present  
auth:  
auth\_url: “{{ item.value.auth\_url }}”  
username: “{{ item.value.username }}”  
password: “{{ item.value.password }}”  
project\_name: “{{ item.value.project\_name }}”  
region\_name: “{{ item.value.region\_name }}”  
name: “{{ item.value.name }}”  
image: “{{ item.value.image }}”  
state: present  
network: “{{ item.value.network }}”  
flavor: “{{ item.value.flavor }}”  
key\_name: “{{ item.value.key\_name }}”  
user\_data: “{{ item.value.user\_data }}”  
with\_dict: “{{ openstack\_hosts }}”  
register: mysqlserver

#- set\_fact: public\_v4=“{{ mysqlserver.server.public\_v4 }}”

- name: output of the registred variable  
debug:  
var: “{{ item.key }}”  
with\_dict: “{{ openstack\_hosts }}”

If I make a debug of “mysqlserver” variable it shows me a big JSON output where I can see the public IP address but “mysqlserver.server.public\_v4” doest not output anything.

I suspect the “with\_dict” calls because without this it works, weiird!  
I need “with\_dict” because I want to have many servers.

Any ideas please?

---

<div class="post-metadata">

**Author:** ![marc.petrivelli](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/marc.petrivelli/32/3773_2.png) [@marc.petrivelli](https://forum.ansible.com/u/marc.petrivelli)\
**Post date:** [September 2, 2017, 5:33pm UTC](https://forum.ansible.com/t/create-dynamic-inventory-for-openstack/25398/2 "2017-09-02T17:33:45Z")

</div>

You say “I suspect the “with\_dict” calls because without this it works, weiird!”. What are you saying “works”?

The registered var from your os\_server task will have the form [http://docs.ansible.com/ansible/latest/playbooks\_loops.html#iterating-over-the-results-of-a-program-execution](http://docs.ansible.com/ansible/latest/playbooks_loops.html#iterating-over-the-results-of-a-program-execution) . I don’t think you want to use with\_dict here.
