Register variable in a loop can't access through with_items

Hi, I’m an ansible noob, and I’m following this tutorial to use the rax module to spin up and configure rackspace servers
http://nicholaskuechler.com/2015/01/09/build-rackspace-cloud-servers-ansible-virtualenv/#comment-550108

It’s great but it’s not dynamic, as you can seemingly only add one server to the dynamic inventory. So I altered it to add servers through with_items like so

tasks:

  • name: Rackspace cloud server build request
    local_action:
    module: rax
    credentials: “{{ credentials }}”
    name: “{{ item }}”
    flavor: “{{ flavor }}”
    image: “{{ image }}”
    region: “{{ region }}”
    files: “{{ files }}”
    wait: yes
    state: present
    networks:
  • private
  • public
    with_items:
  • server-app-01
  • server-app-02register: rax

But the problem is that I can’t access these variables to add them to the dynamic inventory. I tried doing what the documentation said and taking into account the new ‘results’ key in the object, but nothing I do results in it correctly targeting the object value I want. This, to me, is the most logical attempt I have made for the results array, (which you can a stripped out version of here, these servers no longer exist)

  • name: Add each cloud server to host group
    local_action:
    module: add_host
    hostname: “{{ item.instances.name }}”
    ansible_ssh_host: “{{ item.instances.rax_accessipv4 }}”
    ansible_ssh_user: root
    groupname: deploy
    with_items: rax.results

This one results in
One or more undefined variables: ‘list object’ has no attribute ‘rax_accessipv4’

I have tried using rax.results.instances and then using item.name etc, but this results in
One or more undefined variables: ‘unicode object’ has no attribute ‘rax_accessipv4’

I’ve tried too many to list here, for a very long time, but I’ve obviously got confused with how this is supposed to work, can I get some help please?

try using debug module to see the actual structure of the returned data:

debug: var=rax

Hi Brian, thanks for the response.

Perhaps I wasn’t clear in my answer but I actually posted a pastebin link in my second paragraph that shows the data structure output from debug. I stripped out some sensitive information but it is the same structurally.

“This, to me, is the most logical attempt I have made for the results array, (which you can a stripped out version of here, these servers no longer exist)”

Fortunately someone on stack overflow read my question and offered a solution. I don’t fully understand why it uses an array key tbh, but I will look into that on my own.
http://stackoverflow.com/questions/29542433/cant-access-register-variable-in-a-loop/29544680#29544680