Hi List,
I’m trying to create 1 (or more) instances inside different subnet’s where each subnet is a different AZ in Amazon. That way of using AZ’s makes for some better fail-safes.
So:
---
- hosts: localhost
connection: local
gather_facts: no
vars:
#your region
region: eu-west-1
AWS_ACCESS_KEY_ID: snipped
AWS_SECRET_ACCESS_KEY: snipped
ceph_nodes:
1a:
subnet: subnet-snippeda
count: 1
1b:
subnet: subnet-snippedb
count: 1
1c:
subnet: subnet-snippedc
count: 1
tasks:
- name: Maak 1 Ceph host in elke gekozen AZ
local_action:
module: ec2
aws_access_key: "{{ AWS_ACCESS_KEY_ID }}"
aws_secret_key: "{{ AWS_SECRET_ACCESS_KEY }}"
region: "{{ region }}"
vpc_subnet_id: "{{ item.value.subnet }}"
key_name: snipped
instance_type: t2.micro
image: ami-30ff5c47
wait: yes
group: 'backend ceph'
volumes:
- device_name: /dev/sdb
device_type: standard
volume_size: 128
delete_on_termination: false
instance_tags:
Name: ci.ceph.{{ item.key }}
group: ceph{{ item.key }}
environment: development
exact_count: "{{ item.value.count }}"
count_tag:
group: ceph{{ item.key }}
register: ec2
with_dict: ceph_nodes
- debug: var=ec2
when that runs, the variable “ec2” contains:
ok: [localhost] => {
"ec2": {
"changed": true,
"msg": "All items completed",
"results": [
{
"changed": true,
"instance_ids": [
"i-snipped"
],
"instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"dns_name": "",
"ebs_optimized": false,
"hypervisor": "xen",
"id": "i-snipped",
"image_id": "ami-30ff5c47",
"instance_type": "t2.micro",
"kernel": null,
"key_name": "snipped",
"launch_time": "2014-12-30T09:45:55.000Z",
"placement": "eu-west-1a",
"private_dns_name": "ip-10-220-225-9.eu-west-1.compute.internal",
"private_ip": "10.220.225.9",
"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": "hvm"
}
],
"invocation": {
"module_args": "",
"module_name": "ec2"
},
"item": {
"key": "1a",
"value": {
"count": 1,
"subnet": "subnet-snipped"
}
},
"tagged_instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"dns_name": "",
"ebs_optimized": false,
"hypervisor": "xen",
"id": "i-snipped",
"image_id": "ami-30ff5c47",
"instance_type": "t2.micro",
"kernel": null,
"key_name": "snipped",
"launch_time": "2014-12-30T09:45:55.000Z",
"placement": "eu-west-1a",
"private_dns_name": "ip-10-220-225-9.eu-west-1.compute.internal",
"private_ip": "10.220.225.9",
"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": "hvm"
}
]
},
{
"changed": true,
"instance_ids": [
"i-snipped"
],
"instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"dns_name": "",
"ebs_optimized": false,
"hypervisor": "xen",
"id": "i-snipped",
"image_id": "ami-30ff5c47",
"instance_type": "t2.micro",
"kernel": null,
"key_name": "snipped",
"launch_time": "2014-12-30T09:46:17.000Z",
"placement": "eu-west-1c",
"private_dns_name": "ip-10-220-227-66.eu-west-1.compute.internal",
"private_ip": "10.220.227.66",
"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": "hvm"
}
],
"invocation": {
"module_args": "",
"module_name": "ec2"
},
"item": {
"key": "1c",
"value": {
"count": 1,
"subnet": "subnet-snipped"
}
},
"tagged_instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"dns_name": "",
"ebs_optimized": false,
"hypervisor": "xen",
"id": "i-snipped",
"image_id": "ami-30ff5c47",
"instance_type": "t2.micro",
"kernel": null,
"key_name": "snipped",
"launch_time": "2014-12-30T09:46:17.000Z",
"placement": "eu-west-1c",
"private_dns_name": "ip-10-220-227-66.eu-west-1.compute.internal",
"private_ip": "10.220.227.66",
"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": "hvm"
}
]
},
{
"changed": true,
"instance_ids": [
"i-snipped"
],
"instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"dns_name": "",
"ebs_optimized": false,
"hypervisor": "xen",
"id": "i-snipped",
"image_id": "ami-30ff5c47",
"instance_type": "t2.micro",
"kernel": null,
"key_name": "snipped",
"launch_time": "2014-12-30T09:46:45.000Z",
"placement": "eu-west-1b",
"private_dns_name": "ip-10-220-226-191.eu-west-1.compute.internal",
"private_ip": "10.220.226.191",
"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": "hvm"
}
],
"invocation": {
"module_args": "",
"module_name": "ec2"
},
"item": {
"key": "1b",
"value": {
"count": 1,
"subnet": "subnet-snipped"
}
},
"tagged_instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"dns_name": "",
"ebs_optimized": false,
"hypervisor": "xen",
"id": "i-snipped",
"image_id": "ami-30ff5c47",
"instance_type": "t2.micro",
"kernel": null,
"key_name": "snipped",
"launch_time": "2014-12-30T09:46:45.000Z",
"placement": "eu-west-1b",
"private_dns_name": "ip-10-220-226-191.eu-west-1.compute.internal",
"private_ip": "10.220.226.191",
"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": "hvm"
}
]
}
]
}
}
when I then try to add these new hosts to a group:
- name: Add new instances to group
add_host: hostname={{ item.instances.value.private_ip }} groupname=ceph_launched
with_items: ec2.results
I’m getting the error:
TASK: [Add new instances to group] ********************************************
fatal: [localhost] => One or more undefined variables: 'list object' has no attribute 'value'
FATAL: all hosts have already failed -- aborting
I’ve tried a few different ways of referencing the private_ip, but I’m not getting the syntax right.
Can anyone point me in the right direction here?
Thanks!
Mark