| 1 |
--- |
| 2 |
- name: Test EIP allocation |
| 3 |
block: |
| 4 |
# ------------------------------------------------------------------------------------------ |
| 5 |
# Allocate EIP with no condition |
| 6 |
# ------------------------------------------------------------------------------------------ |
| 7 |
- name: Allocate a new EIP with no conditions - check_mode |
| 8 |
amazon.aws.ec2_eip: |
| 9 |
state: present |
| 10 |
tags: "{{ eip_test_tags }}" |
| 11 |
register: eip |
| 12 |
check_mode: true |
| 13 |
|
| 14 |
- ansible.builtin.assert: |
| 15 |
that: |
| 16 |
- eip is changed |
| 17 |
|
| 18 |
- name: Ensure no new EIP was created |
| 19 |
ansible.builtin.include_tasks: tasks/common.yml |
| 20 |
vars: |
| 21 |
has_no_new_eip: true |
| 22 |
|
| 23 |
- name: Allocate a new EIP with no conditions |
| 24 |
amazon.aws.ec2_eip: |
| 25 |
state: present |
| 26 |
tags: "{{ eip_test_tags }}" |
| 27 |
register: eip |
| 28 |
|
| 29 |
- ansible.builtin.assert: |
| 30 |
that: |
| 31 |
- eip is changed |
| 32 |
- "'ec2:CreateTags' not in eip.resource_actions" |
| 33 |
- "'ec2:DeleteTags' not in eip.resource_actions" |
| 34 |
- eip.public_ip is defined and eip.public_ip is ansible.utils.ipv4_address |
| 35 |
- eip.allocation_id is defined and eip.allocation_id.startswith("eipalloc-") |
| 36 |
|
| 37 |
- name: Ensure New EIP was created |
| 38 |
ansible.builtin.include_tasks: tasks/common.yml |
| 39 |
vars: |
| 40 |
has_new_eip: true |
| 41 |
|
| 42 |
- name: Get EIP info via public ip |
| 43 |
amazon.aws.ec2_eip_info: |
| 44 |
filters: |
| 45 |
public-ip: "{{ eip.public_ip }}" |
| 46 |
register: eip_info |
| 47 |
|
| 48 |
- ansible.builtin.assert: |
| 49 |
that: |
| 50 |
- '"addresses" in eip_info' |
| 51 |
- eip_info.addresses | length == 1 |
| 52 |
- eip_info.addresses[0].allocation_id == eip.allocation_id |
| 53 |
- eip_info.addresses[0].domain == "vpc" |
| 54 |
- eip_info.addresses[0].public_ip == eip.public_ip |
| 55 |
- '"AnsibleEIPTestPrefix" in eip_info.addresses[0].tags' |
| 56 |
- eip_info.addresses[0].tags['AnsibleEIPTestPrefix'] == resource_prefix |
| 57 |
|
| 58 |
- name: Get EIP info via allocation id |
| 59 |
amazon.aws.ec2_eip_info: |
| 60 |
filters: |
| 61 |
allocation-id: "{{ eip.allocation_id }}" |
| 62 |
register: eip_info |
| 63 |
|
| 64 |
- ansible.builtin.assert: |
| 65 |
that: |
| 66 |
- '"addresses" in eip_info' |
| 67 |
- eip_info.addresses | length == 1 |
| 68 |
- eip_info.addresses[0].allocation_id == eip.allocation_id |
| 69 |
- eip_info.addresses[0].domain == "vpc" |
| 70 |
- eip_info.addresses[0].public_ip == eip.public_ip |
| 71 |
- '"AnsibleEIPTestPrefix" in eip_info.addresses[0].tags' |
| 72 |
- eip_info.addresses[0].tags['AnsibleEIPTestPrefix'] == resource_prefix |
| 73 |
|
| 74 |
- name: Allocate a new ip (idempotence) - check_mode |
| 75 |
amazon.aws.ec2_eip: |
| 76 |
state: present |
| 77 |
public_ip: "{{ eip.public_ip }}" |
| 78 |
register: eip |
| 79 |
check_mode: true |
| 80 |
|
| 81 |
- ansible.builtin.assert: |
| 82 |
that: |
| 83 |
- eip is not changed |
| 84 |
|
| 85 |
- name: Ensure EIP was not created |
| 86 |
ansible.builtin.include_tasks: tasks/common.yml |
| 87 |
vars: |
| 88 |
has_no_new_eip: true |
| 89 |
|
| 90 |
- name: Allocate a new ip (idempotence) |
| 91 |
amazon.aws.ec2_eip: |
| 92 |
state: present |
| 93 |
public_ip: "{{ eip.public_ip }}" |
| 94 |
register: eip |
| 95 |
|
| 96 |
- ansible.builtin.assert: |
| 97 |
that: |
| 98 |
- eip is not changed |
| 99 |
- eip.public_ip is defined and eip.public_ip is ansible.utils.ipv4_address |
| 100 |
- eip.allocation_id is defined and eip.allocation_id.startswith("eipalloc-") |
| 101 |
|
| 102 |
- name: Ensure EIP was not created |
| 103 |
ansible.builtin.include_tasks: tasks/common.yml |
| 104 |
vars: |
| 105 |
has_no_new_eip: true |
| 106 |
|
| 107 |
# ------------------------------------------------------------------------------------------ |
| 108 |
# Allocate EIP from a pool |
| 109 |
# ------------------------------------------------------------------------------------------ |
| 110 |
- name: Allocate a new EIP from a pool - check_mode |
| 111 |
amazon.aws.ec2_eip: |
| 112 |
state: present |
| 113 |
public_ipv4_pool: amazon |
| 114 |
tags: "{{ eip_test_tags }}" |
| 115 |
register: eip_pool |
| 116 |
check_mode: true |
| 117 |
|
| 118 |
- ansible.builtin.assert: |
| 119 |
that: |
| 120 |
- eip_pool is changed |
| 121 |
|
| 122 |
- name: Ensure EIP was not created |
| 123 |
ansible.builtin.include_tasks: tasks/common.yml |
| 124 |
vars: |
| 125 |
has_no_new_eip: true |
| 126 |
|
| 127 |
- name: Allocate a new EIP from a pool |
| 128 |
amazon.aws.ec2_eip: |
| 129 |
state: present |
| 130 |
public_ipv4_pool: amazon |
| 131 |
tags: "{{ eip_test_tags }}" |
| 132 |
register: eip_pool |
| 133 |
|
| 134 |
- ansible.builtin.assert: |
| 135 |
that: |
| 136 |
- eip_pool is changed |
| 137 |
- eip_pool.public_ip is defined and eip_pool.public_ip is ansible.utils.ipv4_address |
| 138 |
- eip_pool.allocation_id is defined and eip_pool.allocation_id.startswith("eipalloc-") |
| 139 |
|
| 140 |
- name: Ensure new EIP was created |
| 141 |
ansible.builtin.include_tasks: tasks/common.yml |
| 142 |
vars: |
| 143 |
has_new_eip: true |
| 144 |
|
| 145 |
always: |
| 146 |
- name: Delete EIP |
| 147 |
ansible.builtin.include_tasks: tasks/common.yml |
| 148 |
vars: |
| 149 |
delete_eips: true |