2014-02-24 20:37:23 +01:00
|
|
|
---
|
|
|
|
# tasks file for test_ec2_ami
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
- block:
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
|
|
|
# SETUP: vpc, ec2 key pair, subnet, security group, ec2 instance, snapshot
|
2018-04-23 13:54:49 +02:00
|
|
|
- name: set aws_connection_info fact
|
|
|
|
set_fact:
|
|
|
|
aws_connection_info: &aws_connection_info
|
|
|
|
aws_region: '{{aws_region}}'
|
|
|
|
aws_access_key: '{{aws_access_key}}'
|
|
|
|
aws_secret_key: '{{aws_secret_key}}'
|
|
|
|
security_token: '{{security_token}}'
|
|
|
|
no_log: yes
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
- name: create a VPC to work in
|
|
|
|
ec2_vpc_net:
|
|
|
|
cidr_block: 10.0.0.0/24
|
|
|
|
state: present
|
|
|
|
name: '{{ ec2_ami_name }}_setup'
|
|
|
|
resource_tags:
|
|
|
|
Name: '{{ ec2_ami_name }}_setup'
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-15 20:50:08 +02:00
|
|
|
register: setup_vpc
|
|
|
|
|
|
|
|
- name: create a key pair to use for creating an ec2 instance
|
|
|
|
ec2_key:
|
|
|
|
name: '{{ ec2_ami_name }}_setup'
|
|
|
|
state: present
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-15 20:50:08 +02:00
|
|
|
register: setup_key
|
|
|
|
|
|
|
|
- name: create a subnet to use for creating an ec2 instance
|
|
|
|
ec2_vpc_subnet:
|
2017-09-20 07:53:15 +02:00
|
|
|
az: '{{ ec2_region }}a'
|
2017-09-15 20:50:08 +02:00
|
|
|
tags: '{{ ec2_ami_name }}_setup'
|
|
|
|
vpc_id: '{{ setup_vpc.vpc.id }}'
|
|
|
|
cidr: 10.0.0.0/24
|
|
|
|
state: present
|
|
|
|
resource_tags:
|
|
|
|
Name: '{{ ec2_ami_name }}_setup'
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-15 20:50:08 +02:00
|
|
|
register: setup_subnet
|
|
|
|
|
|
|
|
- name: create a security group to use for creating an ec2 instance
|
|
|
|
ec2_group:
|
|
|
|
name: '{{ ec2_ami_name }}_setup'
|
|
|
|
description: 'created by Ansible integration tests'
|
|
|
|
state: present
|
|
|
|
vpc_id: '{{ setup_vpc.vpc.id }}'
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-15 20:50:08 +02:00
|
|
|
register: setup_sg
|
|
|
|
|
|
|
|
- name: provision ec2 instance to create an image
|
|
|
|
ec2:
|
|
|
|
key_name: '{{ setup_key.key.name }}'
|
|
|
|
instance_type: t2.micro
|
|
|
|
state: present
|
2017-10-30 01:20:27 +01:00
|
|
|
image: '{{ ec2_region_images[ec2_region] }}'
|
2017-09-15 20:50:08 +02:00
|
|
|
wait: yes
|
|
|
|
instance_tags:
|
|
|
|
'{{ec2_ami_name}}_instance_setup': 'integration_tests'
|
|
|
|
group_id: '{{ setup_sg.group_id }}'
|
|
|
|
vpc_subnet_id: '{{ setup_subnet.subnet.id }}'
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-15 20:50:08 +02:00
|
|
|
register: setup_instance
|
|
|
|
|
|
|
|
- name: take a snapshot of the instance to create an image
|
|
|
|
ec2_snapshot:
|
|
|
|
instance_id: '{{ setup_instance.instance_ids[0] }}'
|
|
|
|
device_name: /dev/xvda
|
|
|
|
state: present
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-15 20:50:08 +02:00
|
|
|
register: setup_snapshot
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
2018-04-19 01:28:25 +02:00
|
|
|
- name: test clean failure if not providing image_id or name with state=present
|
|
|
|
ec2_ami:
|
|
|
|
instance_id: '{{ setup_instance.instance_ids[0] }}'
|
|
|
|
state: present
|
|
|
|
description: '{{ ec2_ami_description }}'
|
|
|
|
tags:
|
|
|
|
Name: '{{ ec2_ami_name }}_ami'
|
|
|
|
wait: yes
|
|
|
|
root_device_name: /dev/xvda
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2018-04-19 01:28:25 +02:00
|
|
|
register: result
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- name: assert error message is helpful
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.failed
|
|
|
|
- "result.msg == 'one of the following is required: name, image_id'"
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
2017-09-15 20:50:08 +02:00
|
|
|
- name: create an image from the instance
|
|
|
|
ec2_ami:
|
|
|
|
instance_id: '{{ setup_instance.instance_ids[0] }}'
|
|
|
|
state: present
|
|
|
|
name: '{{ ec2_ami_name }}_ami'
|
|
|
|
description: '{{ ec2_ami_description }}'
|
|
|
|
tags:
|
|
|
|
Name: '{{ ec2_ami_name }}_ami'
|
|
|
|
wait: yes
|
|
|
|
root_device_name: /dev/xvda
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-15 20:50:08 +02:00
|
|
|
register: result
|
|
|
|
|
2018-04-23 13:54:49 +02:00
|
|
|
- name: set image id fact for deletion later
|
|
|
|
set_fact:
|
|
|
|
ec2_ami_image_id: "{{ result.image_id }}"
|
|
|
|
|
2017-09-15 20:50:08 +02:00
|
|
|
- name: assert that image has been created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "result.changed"
|
|
|
|
- "result.image_id.startswith('ami-')"
|
2017-10-30 08:45:11 +01:00
|
|
|
- "'Name' in result.tags and result.tags.Name == ec2_ami_name + '_ami'"
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
2017-11-01 23:56:58 +01:00
|
|
|
- name: gather facts about the image created
|
2019-06-10 19:33:38 +02:00
|
|
|
ec2_ami_info:
|
2017-11-01 23:56:58 +01:00
|
|
|
image_ids: '{{ ec2_ami_image_id }}'
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-11-01 23:56:58 +01:00
|
|
|
register: ami_facts_result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: assert that the right image was found
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "ami_facts_result.images[0].image_id == ec2_ami_image_id"
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
2017-09-15 20:50:08 +02:00
|
|
|
- name: delete the image
|
|
|
|
ec2_ami:
|
|
|
|
instance_id: '{{ setup_instance.instance_ids[0] }}'
|
|
|
|
state: absent
|
2017-09-20 07:53:15 +02:00
|
|
|
delete_snapshot: yes
|
2017-09-15 20:50:08 +02:00
|
|
|
name: '{{ ec2_ami_name }}_ami'
|
|
|
|
description: '{{ ec2_ami_description }}'
|
|
|
|
image_id: '{{ result.image_id }}'
|
|
|
|
tags:
|
|
|
|
Name: '{{ ec2_ami_name }}_ami'
|
|
|
|
wait: yes
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-15 20:50:08 +02:00
|
|
|
ignore_errors: true
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that the image has been deleted
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "result.changed"
|
|
|
|
- "'image_id' not in result"
|
2018-05-03 13:48:29 +02:00
|
|
|
- "result.snapshots_deleted"
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
|
|
|
- name: test removing an ami if no image ID is provided (expected failed=true)
|
|
|
|
ec2_ami:
|
|
|
|
state: absent
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-15 20:50:08 +02:00
|
|
|
register: result
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- name: assert that an image ID is required
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "result.failed"
|
2017-10-03 16:17:12 +02:00
|
|
|
- "result.msg == 'state is absent but all of the following are missing: image_id'"
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
|
|
|
- name: create an image from the snapshot
|
|
|
|
ec2_ami:
|
|
|
|
name: '{{ ec2_ami_name }}_ami'
|
|
|
|
description: '{{ ec2_ami_description }}'
|
|
|
|
state: present
|
2017-10-30 08:45:11 +01:00
|
|
|
launch_permissions:
|
|
|
|
user_ids: []
|
2017-09-15 20:50:08 +02:00
|
|
|
tags:
|
|
|
|
Name: '{{ ec2_ami_name }}_ami'
|
|
|
|
root_device_name: /dev/xvda
|
|
|
|
device_mapping:
|
|
|
|
- device_name: /dev/xvda
|
|
|
|
volume_type: gp2
|
|
|
|
size: 8
|
|
|
|
delete_on_termination: true
|
|
|
|
snapshot_id: '{{ setup_snapshot.snapshot_id }}'
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-15 20:50:08 +02:00
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
2018-04-23 13:54:49 +02:00
|
|
|
- name: set image id fact for deletion later
|
|
|
|
set_fact:
|
|
|
|
ec2_ami_image_id: "{{ result.image_id }}"
|
|
|
|
ec2_ami_snapshot: "{{ result.block_device_mapping['/dev/xvda'].snapshot_id }}"
|
|
|
|
|
2017-09-15 20:50:08 +02:00
|
|
|
- name: assert a new ami has been created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "result.changed"
|
|
|
|
- "result.image_id.startswith('ami-')"
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
2017-10-30 08:45:11 +01:00
|
|
|
- name: test default launch permissions idempotence
|
|
|
|
ec2_ami:
|
|
|
|
description: '{{ ec2_ami_description }}'
|
|
|
|
state: present
|
|
|
|
name: '{{ ec2_ami_name }}_ami'
|
|
|
|
tags:
|
|
|
|
Name: '{{ ec2_ami_name }}_ami'
|
|
|
|
root_device_name: /dev/xvda
|
|
|
|
image_id: '{{ result.image_id }}'
|
|
|
|
launch_permissions:
|
|
|
|
user_ids: []
|
|
|
|
device_mapping:
|
|
|
|
- device_name: /dev/xvda
|
|
|
|
volume_type: gp2
|
|
|
|
size: 8
|
|
|
|
delete_on_termination: true
|
|
|
|
snapshot_id: '{{ setup_snapshot.snapshot_id }}'
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-10-30 08:45:11 +01:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert a new ami has not been created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "not result.changed"
|
|
|
|
- "result.image_id.startswith('ami-')"
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
|
|
|
- name: add a tag to the AMI
|
|
|
|
ec2_ami:
|
|
|
|
state: present
|
|
|
|
description: '{{ ec2_ami_description }}'
|
|
|
|
image_id: '{{ result.image_id }}'
|
|
|
|
name: '{{ ec2_ami_name }}_ami'
|
|
|
|
tags:
|
|
|
|
New: Tag
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-15 20:50:08 +02:00
|
|
|
register: result
|
2017-10-30 08:45:11 +01:00
|
|
|
|
|
|
|
- name: assert a tag was added
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'Name' in result.tags and result.tags.Name == ec2_ami_name + '_ami'"
|
|
|
|
- "'New' in result.tags and result.tags.New == 'Tag'"
|
|
|
|
|
|
|
|
- name: use purge_tags to remove a tag from the AMI
|
|
|
|
ec2_ami:
|
|
|
|
state: present
|
|
|
|
description: '{{ ec2_ami_description }}'
|
|
|
|
image_id: '{{ result.image_id }}'
|
|
|
|
name: '{{ ec2_ami_name }}_ami'
|
|
|
|
tags:
|
|
|
|
New: Tag
|
|
|
|
purge_tags: yes
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-10-30 08:45:11 +01:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert a tag was removed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'Name' not in result.tags"
|
|
|
|
- "'New' in result.tags and result.tags.New == 'Tag'"
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
|
|
|
- name: update AMI launch permissions
|
|
|
|
ec2_ami:
|
|
|
|
state: present
|
|
|
|
image_id: '{{ result.image_id }}'
|
|
|
|
description: '{{ ec2_ami_description }}'
|
|
|
|
tags:
|
|
|
|
Name: '{{ ec2_ami_name }}_ami'
|
|
|
|
launch_permissions:
|
|
|
|
group_names: ['all']
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-15 20:50:08 +02:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert launch permissions were updated
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "result.changed"
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
|
|
|
- name: modify the AMI description
|
|
|
|
ec2_ami:
|
|
|
|
state: present
|
|
|
|
image_id: '{{ result.image_id }}'
|
|
|
|
name: '{{ ec2_ami_name }}_ami'
|
|
|
|
description: '{{ ec2_ami_description }}CHANGED'
|
|
|
|
tags:
|
|
|
|
Name: '{{ ec2_ami_name }}_ami'
|
|
|
|
launch_permissions:
|
|
|
|
group_names: ['all']
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-15 20:50:08 +02:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert the description changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "result.changed"
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
2017-10-30 08:45:11 +01:00
|
|
|
- name: remove public launch permissions
|
|
|
|
ec2_ami:
|
|
|
|
state: present
|
|
|
|
image_id: '{{ result.image_id }}'
|
|
|
|
name: '{{ ec2_ami_name }}_ami'
|
|
|
|
tags:
|
|
|
|
Name: '{{ ec2_ami_name }}_ami'
|
|
|
|
launch_permissions:
|
|
|
|
group_names: []
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-10-30 08:45:11 +01:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert launch permissions were updated
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "result.changed"
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
2017-09-20 07:53:15 +02:00
|
|
|
- name: delete ami without deleting the snapshot (default is not to delete)
|
2017-09-15 20:50:08 +02:00
|
|
|
ec2_ami:
|
|
|
|
instance_id: '{{ setup_instance.instance_ids[0] }}'
|
|
|
|
state: absent
|
|
|
|
name: '{{ ec2_ami_name }}_ami'
|
2017-09-20 07:53:15 +02:00
|
|
|
image_id: '{{ ec2_ami_image_id }}'
|
2017-09-15 20:50:08 +02:00
|
|
|
tags:
|
|
|
|
Name: '{{ ec2_ami_name }}_ami'
|
|
|
|
wait: yes
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-15 20:50:08 +02:00
|
|
|
ignore_errors: true
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that the image has been deleted
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "result.changed"
|
|
|
|
- "'image_id' not in result"
|
|
|
|
|
Fix ec2_snapshot_facts for python3
Avoid the following seen when running ec2_ami tests on python3,
presumably because the return type of `map` is different between
python2 and python3.
```
Traceback (most recent call last):
File "/tmp/ansible_e44v27uj/ansible_module_ec2_snapshot_facts.py", line 242, in <module>
main()
File "/tmp/ansible_e44v27uj/ansible_module_ec2_snapshot_facts.py", line 238, in main
list_ec2_snapshots(connection, module)
File "/tmp/ansible_e44v27uj/ansible_module_ec2_snapshot_facts.py", line 193, in list_ec2_snapshots
snapshots = connection.describe_snapshots(SnapshotIds=snapshot_ids, OwnerIds=owner_ids, RestorableByUserIds=restorable_by_user_ids, Filters=filters)
File "/usr/local/lib/python3.5/dist-packages/botocore/client.py", line 312, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.5/dist-packages/botocore/client.py", line 575, in _make_api_call
api_params, operation_model, context=request_context)
File "/usr/local/lib/python3.5/dist-packages/botocore/client.py", line 630, in _convert_to_request_dict
api_params, operation_model)
File "/usr/local/lib/python3.5/dist-packages/botocore/validate.py", line 291, in serialize_to_request
raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter OwnerIds, value: <map object at 0x7ff577511048>, type: <class 'map'>, valid types: <class 'list'>, <class 'tuple'>
```
https://github.com/ansible/ansible/pull/30435#issuecomment-330750498
2017-09-25 05:30:23 +02:00
|
|
|
- name: ensure the snapshot still exists
|
2019-06-10 19:33:38 +02:00
|
|
|
ec2_snapshot_info:
|
Fix ec2_snapshot_facts for python3
Avoid the following seen when running ec2_ami tests on python3,
presumably because the return type of `map` is different between
python2 and python3.
```
Traceback (most recent call last):
File "/tmp/ansible_e44v27uj/ansible_module_ec2_snapshot_facts.py", line 242, in <module>
main()
File "/tmp/ansible_e44v27uj/ansible_module_ec2_snapshot_facts.py", line 238, in main
list_ec2_snapshots(connection, module)
File "/tmp/ansible_e44v27uj/ansible_module_ec2_snapshot_facts.py", line 193, in list_ec2_snapshots
snapshots = connection.describe_snapshots(SnapshotIds=snapshot_ids, OwnerIds=owner_ids, RestorableByUserIds=restorable_by_user_ids, Filters=filters)
File "/usr/local/lib/python3.5/dist-packages/botocore/client.py", line 312, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.5/dist-packages/botocore/client.py", line 575, in _make_api_call
api_params, operation_model, context=request_context)
File "/usr/local/lib/python3.5/dist-packages/botocore/client.py", line 630, in _convert_to_request_dict
api_params, operation_model)
File "/usr/local/lib/python3.5/dist-packages/botocore/validate.py", line 291, in serialize_to_request
raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter OwnerIds, value: <map object at 0x7ff577511048>, type: <class 'map'>, valid types: <class 'list'>, <class 'tuple'>
```
https://github.com/ansible/ansible/pull/30435#issuecomment-330750498
2017-09-25 05:30:23 +02:00
|
|
|
snapshot_ids:
|
|
|
|
- '{{ ec2_ami_snapshot }}'
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
Fix ec2_snapshot_facts for python3
Avoid the following seen when running ec2_ami tests on python3,
presumably because the return type of `map` is different between
python2 and python3.
```
Traceback (most recent call last):
File "/tmp/ansible_e44v27uj/ansible_module_ec2_snapshot_facts.py", line 242, in <module>
main()
File "/tmp/ansible_e44v27uj/ansible_module_ec2_snapshot_facts.py", line 238, in main
list_ec2_snapshots(connection, module)
File "/tmp/ansible_e44v27uj/ansible_module_ec2_snapshot_facts.py", line 193, in list_ec2_snapshots
snapshots = connection.describe_snapshots(SnapshotIds=snapshot_ids, OwnerIds=owner_ids, RestorableByUserIds=restorable_by_user_ids, Filters=filters)
File "/usr/local/lib/python3.5/dist-packages/botocore/client.py", line 312, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.5/dist-packages/botocore/client.py", line 575, in _make_api_call
api_params, operation_model, context=request_context)
File "/usr/local/lib/python3.5/dist-packages/botocore/client.py", line 630, in _convert_to_request_dict
api_params, operation_model)
File "/usr/local/lib/python3.5/dist-packages/botocore/validate.py", line 291, in serialize_to_request
raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter OwnerIds, value: <map object at 0x7ff577511048>, type: <class 'map'>, valid types: <class 'list'>, <class 'tuple'>
```
https://github.com/ansible/ansible/pull/30435#issuecomment-330750498
2017-09-25 05:30:23 +02:00
|
|
|
register: snapshot_result
|
2017-09-20 07:53:15 +02:00
|
|
|
|
Fix ec2_snapshot_facts for python3
Avoid the following seen when running ec2_ami tests on python3,
presumably because the return type of `map` is different between
python2 and python3.
```
Traceback (most recent call last):
File "/tmp/ansible_e44v27uj/ansible_module_ec2_snapshot_facts.py", line 242, in <module>
main()
File "/tmp/ansible_e44v27uj/ansible_module_ec2_snapshot_facts.py", line 238, in main
list_ec2_snapshots(connection, module)
File "/tmp/ansible_e44v27uj/ansible_module_ec2_snapshot_facts.py", line 193, in list_ec2_snapshots
snapshots = connection.describe_snapshots(SnapshotIds=snapshot_ids, OwnerIds=owner_ids, RestorableByUserIds=restorable_by_user_ids, Filters=filters)
File "/usr/local/lib/python3.5/dist-packages/botocore/client.py", line 312, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.5/dist-packages/botocore/client.py", line 575, in _make_api_call
api_params, operation_model, context=request_context)
File "/usr/local/lib/python3.5/dist-packages/botocore/client.py", line 630, in _convert_to_request_dict
api_params, operation_model)
File "/usr/local/lib/python3.5/dist-packages/botocore/validate.py", line 291, in serialize_to_request
raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter OwnerIds, value: <map object at 0x7ff577511048>, type: <class 'map'>, valid types: <class 'list'>, <class 'tuple'>
```
https://github.com/ansible/ansible/pull/30435#issuecomment-330750498
2017-09-25 05:30:23 +02:00
|
|
|
- name: assert the snapshot wasn't deleted
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "snapshot_result.snapshots[0].snapshot_id == ec2_ami_snapshot"
|
2017-09-20 07:53:15 +02:00
|
|
|
|
|
|
|
- name: delete ami for a second time
|
|
|
|
ec2_ami:
|
|
|
|
instance_id: '{{ setup_instance.instance_ids[0] }}'
|
|
|
|
state: absent
|
|
|
|
name: '{{ ec2_ami_name }}_ami'
|
|
|
|
image_id: '{{ ec2_ami_image_id }}'
|
|
|
|
tags:
|
|
|
|
Name: '{{ ec2_ami_name }}_ami'
|
|
|
|
wait: yes
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-20 07:53:15 +02:00
|
|
|
register: result
|
|
|
|
|
2017-10-30 08:45:11 +01:00
|
|
|
- name: assert that image does not exist
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- not result.changed
|
|
|
|
- not result.failed
|
2017-09-20 07:53:15 +02:00
|
|
|
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
2017-09-20 07:53:15 +02:00
|
|
|
always:
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
|
|
|
# TEAR DOWN: snapshot, ec2 instance, ec2 key pair, security group, vpc
|
2017-09-20 07:53:15 +02:00
|
|
|
- name: Announce teardown start
|
|
|
|
debug:
|
|
|
|
msg: "***** TESTING COMPLETE. COMMENCE TEARDOWN *****"
|
|
|
|
|
|
|
|
- name: delete ami
|
|
|
|
ec2_ami:
|
|
|
|
state: absent
|
|
|
|
image_id: "{{ ec2_ami_image_id }}"
|
|
|
|
name: '{{ ec2_ami_name }}_ami'
|
|
|
|
wait: yes
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-20 07:53:15 +02:00
|
|
|
ignore_errors: yes
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
- name: remove setup snapshot of ec2 instance
|
|
|
|
ec2_snapshot:
|
|
|
|
state: absent
|
|
|
|
snapshot_id: '{{ setup_snapshot.snapshot_id }}'
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-20 07:53:15 +02:00
|
|
|
ignore_errors: yes
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
- name: remove setup ec2 instance
|
|
|
|
ec2:
|
|
|
|
instance_type: t2.micro
|
|
|
|
instance_ids: '{{ setup_instance.instance_ids }}'
|
|
|
|
state: absent
|
|
|
|
wait: yes
|
|
|
|
instance_tags:
|
|
|
|
'{{ec2_ami_name}}_instance_setup': 'integration_tests'
|
|
|
|
group_id: '{{ setup_sg.group_id }}'
|
|
|
|
vpc_subnet_id: '{{ setup_subnet.subnet.id }}'
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-20 07:53:15 +02:00
|
|
|
ignore_errors: yes
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
- name: remove setup keypair
|
|
|
|
ec2_key:
|
|
|
|
name: '{{ec2_ami_name}}_setup'
|
|
|
|
state: absent
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-20 07:53:15 +02:00
|
|
|
ignore_errors: yes
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
- name: remove setup security group
|
|
|
|
ec2_group:
|
|
|
|
name: '{{ ec2_ami_name }}_setup'
|
|
|
|
description: 'created by Ansible integration tests'
|
|
|
|
state: absent
|
|
|
|
vpc_id: '{{ setup_vpc.vpc.id }}'
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-20 07:53:15 +02:00
|
|
|
ignore_errors: yes
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
- name: remove setup subnet
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
az: '{{ ec2_region }}a'
|
|
|
|
tags: '{{ec2_ami_name}}_setup'
|
|
|
|
vpc_id: '{{ setup_vpc.vpc.id }}'
|
|
|
|
cidr: 10.0.0.0/24
|
|
|
|
state: absent
|
|
|
|
resource_tags:
|
|
|
|
Name: '{{ ec2_ami_name }}_setup'
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-20 07:53:15 +02:00
|
|
|
ignore_errors: yes
|
2017-09-15 20:50:08 +02:00
|
|
|
|
|
|
|
- name: remove setup VPC
|
|
|
|
ec2_vpc_net:
|
|
|
|
cidr_block: 10.0.0.0/24
|
|
|
|
state: absent
|
|
|
|
name: '{{ ec2_ami_name }}_setup'
|
|
|
|
resource_tags:
|
|
|
|
Name: '{{ ec2_ami_name }}_setup'
|
2018-04-23 13:54:49 +02:00
|
|
|
<<: *aws_connection_info
|
2017-09-20 07:53:15 +02:00
|
|
|
ignore_errors: yes
|