summaryrefslogtreecommitdiff
path: root/test/integration/targets/incidental_ec2_instance/roles/ec2_instance/tasks/block_devices.yml
blob: 0a8ab63f08b7c63d23832cc16e74843ed16eecc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
- block:
  - name: "New instance with an extra block device"
    ec2_instance:
      state: present
      name: "{{ resource_prefix }}-test-ebs-vols"
      image_id: "{{ ec2_ami_image }}"
      vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
      volumes:
      - device_name: /dev/sdb
        ebs:
          volume_size: 20
          delete_on_termination: true
          volume_type: standard
      tags:
        TestId: "{{ ec2_instance_tag_TestId }}"
      instance_type: "{{ ec2_instance_type }}"
      wait: true
    register: block_device_instances

  - name: "Gather instance info"
    ec2_instance_info:
      filters:
        "tag:Name": "{{ resource_prefix }}-test-ebs-vols"
    register: block_device_instances_info

  - assert:
      that:
      - block_device_instances is not failed
      - block_device_instances is changed
      - block_device_instances_info.instances[0].block_device_mappings[0]
      - block_device_instances_info.instances[0].block_device_mappings[1]
      - block_device_instances_info.instances[0].block_device_mappings[1].device_name == '/dev/sdb'

  - name: "New instance with an extra block device (check mode)"
    ec2_instance:
      state: present
      name: "{{ resource_prefix }}-test-ebs-vols-checkmode"
      image_id: "{{ ec2_ami_image }}"
      vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
      volumes:
      - device_name: /dev/sdb
        ebs:
          volume_size: 20
          delete_on_termination: true
          volume_type: standard
      tags:
        TestId: "{{ ec2_instance_tag_TestId }}"
      instance_type: "{{ ec2_instance_type }}"
    check_mode: yes

  - name: "fact presented ec2 instance"
    ec2_instance_info:
      filters:
        "tag:Name": "{{ resource_prefix }}-test-ebs-vols"
        "instance-state-name": "running"
    register: presented_instance_fact

  - name: "fact checkmode ec2 instance"
    ec2_instance_info:
      filters:
        "tag:Name": "{{ resource_prefix }}-test-ebs-vols-checkmode"
    register: checkmode_instance_fact

  - name: "Confirm whether the check mode is working normally."
    assert:
      that:
        - "{{ presented_instance_fact.instances | length }} > 0"
        - "{{ checkmode_instance_fact.instances | length }} == 0"

  - name: "Terminate instances"
    ec2_instance:
      state: absent
      instance_ids: "{{ block_device_instances.instance_ids }}"

  always:
  - name: "Terminate block_devices instances"
    ec2_instance:
      state: absent
      filters:
        "tag:TestId": "{{ ec2_instance_tag_TestId }}"
      wait: yes
    ignore_errors: yes