That's what I thought but I get an error when trying to pass it to an ebs
volume attachment.
- name: Create and attach ec2 volume
ec2_vol:
instance: "{{ item.instance_ids }}"
volume_size: "{{ volume_size }}"
volume_type: "{{ volume_type }}"
device_name: "/dev/xvd{{ drive }}"
region: us-west-2
with_items: "{{ ec2a.results }}"
when: ebs is defined
dumbledore@ansible1a:/etc/ansible > ansible-playbook
/etc/ansible/playbooks/db_ec2.yml -e 'env=qa num=1 ebs=true'
__________________
< PLAY [localhost] >
------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
______________________
< TASK [db_ec2 : fail] >
----------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
_______________________
< TASK [db_ec2 : debug] >
-----------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
ok: [localhost] => {
"msg": "If you need to change any default variables for this playbook
edit vars/qa.yml and vars/ebs.yml for ebs configs"
}
________________________________________________
< TASK [db_ec2 : Create EC2 instance for zone A] >
------------------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
changed: [localhost] => (item=1)
_______________________
< TASK [db_ec2 : debug] >
-----------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
ok: [localhost] => (item={u'changed': True, '_ansible_no_log': False,
u'instances': [{u'kernel': None, u'root_device_type': u'ebs',
u'private_dns_name': u'ip-10-50-45-172.us-west-2.compute.internal',
u'public_ip': None, u'private_ip': u'10.50.45.172', u'id': u'i-3a0e8822',
u'ebs_optimized': False, u'state': u'running', u'virtualization_type':
u'hvm', u'architecture': u'x86_64', u'ramdisk': None,
u'block_device_mapping': {u'/dev/sda1': {u'status': u'attached',
u'delete_on_termination': True, u'volume_id': u'vol-c4fc554c'}},
u'key_name': u'ccpkey', u'image_id': u'ami-55e31a35', u'tenancy':
u'default', u'groups': {u'sg-749f3c0d': u'qa-ssh', u'sg-8f983bf6':
u'qa-db'}, u'public_dns_name': u'', u'state_code': 16, u'tags':
{u'envtype': u'qa-db', u'Name': u'db1a.qa'}, u'placement': u'us-west-2a',
u'ami_launch_index': u'0', u'dns_name': u'', u'region': u'us-west-2',
u'launch_time': u'2016-09-28T18:38:53.000Z', u'instance_type':
u'm4.xlarge', u'root_device_name': u'/dev/sda1', u'hypervisor': u'xen'}],
'_ansible_item_result': True, u'instance_ids': [u'i-3a0e8822'], 'item':
u'1', u'tagged_instances': [], 'invocation': {'module_name': u'ec2',
u'module_args': {u'kernel': None, u'image': u'ami-55e31a35', u'user_data':
None, u'group': [u'qa-db', u'qa-ssh'], u'count_tag': None, u'private_ip':
None, u'spot_type': u'one-time', u'ec2_url': None, u'id': None,
u'source_dest_check': True, u'aws_secret_key': None, u'spot_wait_timeout':
u'600', u'monitoring': False, u'zone': u'us-west-2a', u'exact_count': None,
u'ebs_optimized': False, u'state': u'present', u'placement_group': None,
u'spot_launch_group': None, u'ramdisk': None, u'key_name': u'ccpkey',
u'vpc_subnet_id': u'subnet-5d625c39', u'instance_ids': None, u'tenancy':
u'default', u'profile': None, u'assign_public_ip': False, u'spot_price':
None, u'wait': True, u'count': 1, u'aws_access_key': None,
u'instance_profile_name': None, u'security_token': None, u'region':
u'us-west-2', u'network_interfaces': None, u'termination_protection':
False, u'instance_type': u'm4.xlarge', u'wait_timeout': u'300', u'volumes':
None, u'instance_tags': {u'envtype': u'qa-db', u'Name': u'db1a.qa'},
u'group_id': None, u'validate_certs': True}}}) => {
"item": {
"changed": true,
"instance_ids": [
"i-3a0e8822"
],
"instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"block_device_mapping": {
"/dev/sda1": {
"delete_on_termination": true,
"status": "attached",
"volume_id": "vol-c4fc554c"
}
},
"dns_name": "",
"ebs_optimized": false,
"groups": {
"sg-749f3c0d": "qa-ssh",
"sg-8f983bf6": "qa-db"
},
"hypervisor": "xen",
"id": "i-3a0e8822",
"image_id": "ami-55e31a35",
"instance_type": "m4.xlarge",
"kernel": null,
"key_name": "ccpkey",
"launch_time": "2016-09-28T18:38:53.000Z",
"placement": "us-west-2a",
"private_dns_name":
"ip-10-50-45-172.us-west-2.compute.internal",
"private_ip": "10.50.45.172",
"public_dns_name": "",
"public_ip": null,
"ramdisk": null,
"region": "us-west-2",
"root_device_name": "/dev/sda1",
"root_device_type": "ebs",
"state": "running",
"state_code": 16,
"tags": {
"Name": "db1a.qa",
"envtype": "qa-db"
},
"tenancy": "default",
"virtualization_type": "hvm"
}
],
"invocation": {
"module_args": {
"assign_public_ip": false,
"aws_access_key": null,
"aws_secret_key": null,
"count": 1,
"count_tag": null,
"ebs_optimized": false,
"ec2_url": null,
"exact_count": null,
"group": [
"qa-db",
"qa-ssh"
],
"group_id": null,
"id": null,
"image": "ami-55e31a35",
"instance_ids": null,
"instance_profile_name": null,
"instance_tags": {
"Name": "db1a.qa",
"envtype": "qa-db"
},
"instance_type": "m4.xlarge",
"kernel": null,
"key_name": "ccpkey",
"monitoring": false,
"network_interfaces": null,
"placement_group": null,
"private_ip": null,
"profile": null,
"ramdisk": null,
"region": "us-west-2",
"security_token": null,
"source_dest_check": true,
"spot_launch_group": null,
"spot_price": null,
"spot_type": "one-time",
"spot_wait_timeout": "600",
"state": "present",
"tenancy": "default",
"termination_protection": false,
"user_data": null,
"validate_certs": true,
"volumes": null,
"vpc_subnet_id": "subnet-5d625c39",
"wait": true,
"wait_timeout": "300",
"zone": "us-west-2a"
},
"module_name": "ec2"
},
"item": "1",
"tagged_instances": []
},
"msg": [
"i-3a0e8822"
]
}
______________________________________________
< TASK [db_ec2 : Create and attach ec2 volume] >
----------------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
failed: [localhost] (item={u'changed': True, '_ansible_no_log': False,
u'instances': [{u'kernel': None, u'root_device_type': u'ebs',
u'private_dns_name': u'ip-10-50-45-172.us-west-2.compute.internal',
u'public_ip': None, u'private_ip': u'10.50.45.172', u'id': u'i-3a0e8822',
u'ebs_optimized': False, u'state': u'running', u'virtualization_type':
u'hvm', u'architecture': u'x86_64', u'ramdisk': None,
u'block_device_mapping': {u'/dev/sda1': {u'status': u'attached',
u'delete_on_termination': True, u'volume_id': u'vol-c4fc554c'}},
u'key_name': u'ccpkey', u'image_id': u'ami-55e31a35', u'tenancy':
u'default', u'groups': {u'sg-749f3c0d': u'qa-ssh', u'sg-8f983bf6':
u'qa-db'}, u'public_dns_name': u'', u'state_code': 16, u'tags':
{u'envtype': u'qa-db', u'Name': u'db1a.qa'}, u'placement': u'us-west-2a',
u'ami_launch_index': u'0', u'dns_name': u'', u'region': u'us-west-2',
u'launch_time': u'2016-09-28T18:38:53.000Z', u'instance_type':
u'm4.xlarge', u'root_device_name': u'/dev/sda1', u'hypervisor': u'xen'}],
'_ansible_item_result': True, u'instance_ids': [u'i-3a0e8822'], 'item':
u'1', u'tagged_instances': [], 'invocation': {'module_name': u'ec2',
u'module_args': {u'kernel': None, u'image': u'ami-55e31a35', u'user_data':
None, u'group': [u'qa-db', u'qa-ssh'], u'count_tag': None, u'private_ip':
None, u'spot_type': u'one-time', u'ec2_url': None, u'id': None,
u'source_dest_check': True, u'aws_secret_key': None, u'spot_wait_timeout':
u'600', u'monitoring': False, u'zone': u'us-west-2a', u'exact_count': None,
u'ebs_optimized': False, u'state': u'present', u'placement_group': None,
u'spot_launch_group': None, u'ramdisk': None, u'key_name': u'ccpkey',
u'vpc_subnet_id': u'subnet-5d625c39', u'instance_ids': None, u'tenancy':
u'default', u'profile': None, u'assign_public_ip': False, u'spot_price':
None, u'wait': True, u'count': 1, u'aws_access_key': None,
u'instance_profile_name': None, u'security_token': None, u'region':
u'us-west-2', u'network_interfaces': None, u'termination_protection':
False, u'instance_type': u'm4.xlarge', u'wait_timeout': u'300', u'volumes':
None, u'instance_tags': {u'envtype': u'qa-db', u'Name': u'db1a.qa'},
u'group_id': None, u'validate_certs': True}}}) => {"failed": true, "item":
{"changed": true, "instance_ids": ["i-3a0e8822"], "instances":
[{"ami_launch_index": "0", "architecture": "x86_64",
"block_device_mapping": {"/dev/sda1": {"delete_on_termination": true,
"status": "attached", "volume_id": "vol-c4fc554c"}}, "dns_name": "",
"ebs_optimized": false, "groups": {"sg-749f3c0d": "qa-ssh", "sg-8f983bf6":
"qa-db"}, "hypervisor": "xen", "id": "i-3a0e8822", "image_id":
"ami-55e31a35", "instance_type": "m4.xlarge", "kernel": null, "key_name":
"ccpkey", "launch_time": "2016-09-28T18:38:53.000Z", "placement":
"us-west-2a", "private_dns_name":
"ip-10-50-45-172.us-west-2.compute.internal", "private_ip": "10.50.45.172",
"public_dns_name": "", "public_ip": null, "ramdisk": null, "region":
"us-west-2", "root_device_name": "/dev/sda1", "root_device_type": "ebs",
"state": "running", "state_code": 16, "tags": {"Name": "db1a.qa",
"envtype": "qa-db"}, "tenancy": "default", "virtualization_type": "hvm"}],
"invocation": {"module_args": {"assign_public_ip": false, "aws_access_key":
null, "aws_secret_key": null, "count": 1, "count_tag": null,
"ebs_optimized": false, "ec2_url": null, "exact_count": null, "group":
["qa-db", "qa-ssh"], "group_id": null, "id": null, "image": "ami-55e31a35",
"instance_ids": null, "instance_profile_name": null, "instance_tags":
{"Name": "db1a.qa", "envtype": "qa-db"}, "instance_type": "m4.xlarge",
"kernel": null, "key_name": "ccpkey", "monitoring": false,
"network_interfaces": null, "placement_group": null, "private_ip": null,
"profile": null, "ramdisk": null, "region": "us-west-2", "security_token":
null, "source_dest_check": true, "spot_launch_group": null, "spot_price":
null, "spot_type": "one-time", "spot_wait_timeout": "600", "state":
"present", "tenancy": "default", "termination_protection": false,
"user_data": null, "validate_certs": true, "volumes": null,
"vpc_subnet_id": "subnet-5d625c39", "wait": true, "wait_timeout": "300",
"zone": "us-west-2a"}, "module_name": "ec2"}, "item": "1",
"tagged_instances": []}, "msg": "Invalid id: \"['i-3a0e8822']\""}
Tells me invalid ID. I have wait set to wait for the instance to be
running.
Not sure what is going on here.
*Christopher Stobie*
*Lead DevOps Engineer*
*ClearCapital, Inc.*
(469) 682 2933
[email protected]
On Wed, Sep 28, 2016 at 11:15 AM, Kai Stian Olstad <
[email protected]> wrote:
> On 28. sep. 2016 19:25, Christopher Stobie wrote:
>
>> OK that makes total sense.
>>
>> Follow up question, what is the syntax in ansible to iterate over every
>> entry in the array.
>>
>> So for individual results you do ec2.results[0].instance_ids.
>>
>> What do you do for all results or to loop over this to get every instance
>> id from multiple entries.
>>
>> like ec2.results[i].instance_ids or something?
>>
>
> - debug: var=item.instance_ids
> with_items: "{{ ec2.results }}"
>
> --
> Kai Stian Olstad
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/ansible-project/f7fd7d96-41c3-4684-e395-8dfa6a852140%40olstad.com.
>
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAHFHBDoUg%2Br9d3jdww_900fBOiwFoe4V6ABfQ9960OKWhpAVpg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.