I am sure that I miss something obvious... but after having tried for a few hours, I just don't know where to look for a solution ...
I have the following playbook to create a new amazon instance and do a few things with it.
The instance is created correctly, but when I try to access to ec2_info.instances. private_ip variables, the playbook fail with an undefined variable error ...
Many thanks in advance.
** playbook:
---
- hosts: 127.0.0.1
connection: local
gather_facts: True
vars:
keypair: mykey
fqdn: "{{ hostname }}.{{ dnsdomain }}"
tasks:
- name: create a vm
local_action:
module: ec2
image: ami-75342c01
count: 1
instance_type: m1.large
group:
- J2EE
- default
key_name: "{{ keypair }}"
vpc_subnet_id: subnet
user_data: "{{ hostname }}.{{ dnsdomain }}"
instance_tags: '{ "QA": "group", "Name": "{{ hostname }}" }'
volumes:
- device_name: /dev/sda1
volume_size: 10
- device_name: /dev/sdb
ephemeral: ephemeral0
- device_name: /dev/sdc
volume_size: 25
wait: true
wait_timeout: 500
state: present
register: ec2_info
- name: register DNS name
command: dnsupdate.py -s localhost -k Kddnsupdate.key -x add {{ fqdn }} 300 A {{ ec2_info.instances.private_ip }}
sudo: yes
remote_user: user
delegate_to: dns_server
- name: add new instance to inventory
add_host: name={{ hostname }} groups=ci hostname={{ fqdn }} ansible_ssh_host={{ ec2_info.instances.private_ip }} ansible_ssh_private_key_file=~/.ssh/{{ keypair }}.pem
- name: wait for instance to start
wait_for: state=started host={{ ec2_info.instances.private_ip }} port=22
** error message:
TASK: [register DNS name] *****************************************************
fatal: [127.0.0.1] => One or more undefined variables: 'list' object has no attribute 'private_ip'
FATAL: all hosts have already failed -- aborting
** with a "debug=ec2_info.instances":
"ec2_info.instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"dns_name": "",
"hypervisor": "xen",
"id": "i-d43324",
"image_id": "ami-7",
"instance_type": "m1.large",
"kernel": "aki-54425520",
"key_name": "ContinuousQA",
"launch_time": "2014-04-07T12:30:29.000Z",
"placement": "eu-west-1b",
"private_ip": "172.16.4.127",
"public_dns_name": "",
"public_ip": null,
"ramdisk": null,
"region": "eu-west-1",
"root_device_name": "/dev/sda1",
"root_device_type": "ebs",
"state": "running",
"state_code": 16,
"virtualization_type": "paravirtual"
}
]
}