4d775cbbf1
* change variable name from isinstance to is_instance (prevent overriding builtin function) * Added support for: - Filtering existing Elastic IPs based on a tag name or it's value (when reuse_existing_ip_allowed is true) - Allocating new Elastic IPs from a given IPv4 pool (BYOIP support) * yamllint corrections * added examples for: - tag_name, - tag_value - public_ipv4_pool * remove aliases * Added changelog fragment * added integration tests for ec2_eip module * removed space to trigger rebuild
145 lines
No EOL
4.8 KiB
YAML
145 lines
No EOL
4.8 KiB
YAML
---
|
|
- name: Integration testing for ec2_eip
|
|
block:
|
|
|
|
- name: set up aws connection info
|
|
set_fact:
|
|
aws_connection_info: &aws_connection_info
|
|
aws_access_key: "{{ aws_access_key }}"
|
|
aws_secret_key: "{{ aws_secret_key }}"
|
|
security_token: "{{ security_token }}"
|
|
region: "{{ aws_region }}"
|
|
no_log: True
|
|
|
|
- name: Allocate a new eip - attempt reusing unallocated ones
|
|
ec2_eip:
|
|
state: present
|
|
in_vpc: yes
|
|
reuse_existing_ip_allowed: yes
|
|
<<: *aws_connection_info
|
|
register: eip
|
|
|
|
- assert:
|
|
that:
|
|
- eip is defined
|
|
- eip.public_ip is defined and eip.public_ip != ""
|
|
- eip.allocation_id is defined and eip.allocation_id != ""
|
|
|
|
- name: Allocate a new eip
|
|
ec2_eip:
|
|
state: present
|
|
in_vpc: yes
|
|
<<: *aws_connection_info
|
|
register: new_eip
|
|
|
|
- assert:
|
|
that:
|
|
- new_eip is defined
|
|
- new_eip is changed
|
|
- new_eip.public_ip is defined and new_eip.public_ip != ""
|
|
- new_eip.allocation_id is defined and new_eip.allocation_id != ""
|
|
|
|
- name: Match an existing eip (changed == false)
|
|
ec2_eip:
|
|
state: present
|
|
in_vpc: yes
|
|
<<: *aws_connection_info
|
|
public_ip: "{{ eip.public_ip }}"
|
|
register: existing_eip
|
|
|
|
- assert:
|
|
that:
|
|
- existing_eip is defined
|
|
- existing_eip is not changed
|
|
- existing_eip.public_ip is defined and existing_eip.public_ip != ""
|
|
- existing_eip.allocation_id is defined and existing_eip.allocation_id != ""
|
|
|
|
- name: attempt reusing an existing eip with a tag (or allocate a new one)
|
|
ec2_eip:
|
|
state: present
|
|
in_vpc: yes
|
|
<<: *aws_connection_info
|
|
reuse_existing_ip_allowed: yes
|
|
tag_name: Team
|
|
register: tagged_eip
|
|
|
|
- assert:
|
|
that:
|
|
- tagged_eip is defined
|
|
- tagged_eip.public_ip is defined and tagged_eip.public_ip != ""
|
|
- tagged_eip.allocation_id is defined and tagged_eip.allocation_id != ""
|
|
|
|
- name: attempt reusing an existing eip with a tag and it's value (or allocate a new one)
|
|
ec2_eip:
|
|
state: present
|
|
in_vpc: yes
|
|
<<: *aws_connection_info
|
|
public_ip: "{{ eip.public_ip }}"
|
|
reuse_existing_ip_allowed: yes
|
|
tag_name: Team
|
|
tag_value: Backend
|
|
register: backend_eip
|
|
|
|
- assert:
|
|
that:
|
|
- backend_eip is defined
|
|
- backend_eip.public_ip is defined and backend_eip.public_ip != ""
|
|
- backend_eip.allocation_id is defined and backend_eip.allocation_id != ""
|
|
|
|
- name: attempt reusing an existing eip with a tag and it's value (or allocate a new one from pool)
|
|
ec2_eip:
|
|
state: present
|
|
in_vpc: yes
|
|
<<: *aws_connection_info
|
|
reuse_existing_ip_allowed: yes
|
|
tag_name: Team
|
|
tag_value: Backend
|
|
public_ipv4_pool: amazon
|
|
register: amazon_eip
|
|
|
|
- assert:
|
|
that:
|
|
- amazon_eip is defined
|
|
- amazon_eip.public_ip is defined and amazon_eip.public_ip != ""
|
|
- amazon_eip.allocation_id is defined and amazon_eip.allocation_id != ""
|
|
|
|
- name: allocate a new eip from a pool
|
|
ec2_eip:
|
|
state: present
|
|
in_vpc: yes
|
|
<<: *aws_connection_info
|
|
public_ipv4_pool: amazon
|
|
register: pool_eip
|
|
|
|
- assert:
|
|
that:
|
|
- pool_eip is defined
|
|
- pool_eip is changed
|
|
- pool_eip.public_ip is defined and pool_eip.public_ip != ""
|
|
- pool_eip.allocation_id is defined and pool_eip.allocation_id != ""
|
|
|
|
always:
|
|
- debug: msg="{{ item }}"
|
|
when: item is defined and item.public_ip is defined and item.allocation_id is defined
|
|
loop:
|
|
- eip
|
|
- new_eip
|
|
- pool_eip
|
|
- tagged_eip
|
|
- backend_eip
|
|
- amazon_eip
|
|
- name: Cleanup newly allocated eip
|
|
ec2_eip:
|
|
state: absent
|
|
public_ip: "{{ item.public_ip }}"
|
|
in_vpc: yes
|
|
<<: *aws_connection_info
|
|
when: item is defined and item is changed and item.public_ip is defined and item.public_ip != ""
|
|
loop:
|
|
- "{{ eip }}"
|
|
- "{{ new_eip }}"
|
|
- "{{ pool_eip }}"
|
|
- "{{ tagged_eip }}"
|
|
- "{{ backend_eip }}"
|
|
- "{{ amazon_eip }}"
|
|
... |