# how to reference metadata in rax\_facts

**URL:** <https://forum.ansible.com/t/how-to-reference-metadata-in-rax-facts/15395>\
**Category:** Ansible Project\
**Created:** [June 3, 2014, 4:29pm UTC](https://forum.ansible.com/t/how-to-reference-metadata-in-rax-facts/15395 "2014-06-03T16:29:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jurgen\_Coetsiers2](https://avatars.discourse-cdn.com/v4/letter/j/aca169/32.png) [@Jurgen\_Coetsiers2](https://forum.ansible.com/u/Jurgen_Coetsiers2)\
**Post date:** [June 3, 2014, 4:29pm UTC](https://forum.ansible.com/t/how-to-reference-metadata-in-rax-facts/15395/1 "2014-06-03T16:29:19Z")

</div>

Hi All,

My Rackspace cloud servers are under managed services and under RackConnect services. This means than when they are built, first 2 other scripts need to run before I can actually use the server to provision it.

The peculiar thing is that during the RackConnect script the public ip of the server changes, so it in validates the data you “register” using the rax module when adding a server.

The fact is that we do not know precise when these build scripts have finished running. The only way to figure it out is either through the presence of a file in the servers /tmp directory or by querying the fact data received through the rackspace api. It should have a NVP set in the metatags field.

So basically what I want to do is:

- create cloud server
- poll factsdata until certain values are set
- provision the server

The documentation of the rax\_facts module does not provide a lot of info, event when copying the sample is fails due to “{{ rax\_accessipv4 }}” not existing…

So who can help me out here or me into the right direction?

My current playbook:

- name: Wait for Rackspace Managed Service provisioning completion  
hosts: raxtest  
gather\_facts: False  
remote\_user: root  
tasks:
- name: Get meta data and check for completion of setup  
local\_action:  
module: rax\_facts  
api\_key:   
username:   
register: result  
name: “{{ inventory\_hostname }}”  
set\_fact: managed\_done = “{{rax\_metadata.rax\_service\_level\_automation}}”  
set\_fact: ansible\_ssh\_host = “{{ rax\_accessipv4 }}”  
until: managed\_done = “Complete”

retries: 20  
delay: 30

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 3, 2014, 4:51pm UTC](https://forum.ansible.com/t/how-to-reference-metadata-in-rax-facts/15395/2 "2014-06-03T16:51:00Z")

</div>

I have some sample plays that show how to wait for RackConnect automation and the Managed Cloud automation to complete before moving on. I haven’t gotten around to adding it to the Rackspace guide, but hope to do so soon.

You can see those sample playbooks:

[https://github.com/sivel/ansible-samples/tree/master/rackconnect](https://github.com/sivel/ansible-samples/tree/master/rackconnect)

In your specific case, the following lines are probably what you are in need of [https://github.com/sivel/ansible-samples/blob/master/rackconnect/rackconnect-push-mode.yml#L49-L58](https://github.com/sivel/ansible-samples/blob/master/rackconnect/rackconnect-push-mode.yml#L49-L58)

On another note, you cannot call a module from within another module. So your attempts at running set\_fact inside of a local\_action for rax\_facts just can’t work.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 3, 2014, 5:19pm UTC](https://forum.ansible.com/t/how-to-reference-metadata-in-rax-facts/15395/3 "2014-06-03T17:19:01Z")

</div>

PR has been submitted to include these examples in the Rackspace guide: [https://github.com/ansible/ansible/pull/7650](https://github.com/ansible/ansible/pull/7650)

---

<div class="post-metadata">

**Author:** ![Jurgen\_Coetsiers2](https://avatars.discourse-cdn.com/v4/letter/j/aca169/32.png) [@Jurgen\_Coetsiers2](https://forum.ansible.com/u/Jurgen_Coetsiers2)\
**Post date:** [June 3, 2014, 11:22pm UTC](https://forum.ansible.com/t/how-to-reference-metadata-in-rax-facts/15395/4 "2014-06-03T23:22:55Z")

</div>

Matt,

tx this was of great help!

We saw that wen adding the metadata for the LB Pools

meta:  
RackConnectLBPool: marlintest

that strangely the name that is captured by the api is:

u’marlintest’ and as such the rackconnect script fails.

I tried putting " around it but no luck

Any ideas?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 3, 2014, 11:26pm UTC](https://forum.ansible.com/t/how-to-reference-metadata-in-rax-facts/15395/5 "2014-06-03T23:26:46Z")

</div>

That issue is fixed in another pull request which is waiting to be merged:

[https://github.com/ansible/ansible/pull/7122](https://github.com/ansible/ansible/pull/7122)

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 4, 2014, 4:15pm UTC](https://forum.ansible.com/t/how-to-reference-metadata-in-rax-facts/15395/6 "2014-06-04T16:15:16Z")

</div>

PR #7122 has just been merged. It also includes a new module “rax\_meta” for more easily allowing metadata updates on cloud servers.

Both “rax” and “rax\_meta” use the improved metadata normalization code.

---

<div class="post-metadata">

**Author:** ![Jurgen\_Coetsiers1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Jurgen\_Coetsiers1](https://forum.ansible.com/u/Jurgen_Coetsiers1)\
**Post date:** [June 4, 2014, 7:03pm UTC](https://forum.ansible.com/t/how-to-reference-metadata-in-rax-facts/15395/7 "2014-06-04T19:03:31Z")

</div>

Matt,

Great, meta data is now correctly put into the api call…

However we still are having some problems. Sometimes the script goes faster then the meta data becomes available:

fatal: [web6] =\> error while evaluating conditional: rax\_facts.ansible\_facts.rax\_metadata[‘rackconnect\_automation\_status’]|default(‘’) == ‘DEPLOYED’

We checked and the automation status metadata is not yet present and as such the check fails.

Jurgen

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 4, 2014, 8:20pm UTC](https://forum.ansible.com/t/how-to-reference-metadata-in-rax-facts/15395/8 "2014-06-04T20:20:45Z")

</div>

The “|default(‘’)” should handle individual meta data keys not being available.

I’ve never seen this happen. You might try running with -v to see what the calls to rax\_facts are returning. rax\_metadata should always be present and should always be a dict.
