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?