mirror of https://github.com/ansible/ansible.git
Migrate ec2_eip module to boto3 (#61575)
* Migrate ec2_eip module to boto3 This patch is a step towards the integration of several PRs that have attempted to migrate this code closes #55190 closes #45478 Follow-up PRs will address the outstanding changes made in #55190pull/61655/merge
parent
00add5b668
commit
2ebeadfc14
@ -1,145 +1,144 @@
|
|||||||
---
|
---
|
||||||
- name: Integration testing for ec2_eip
|
- name: Integration testing for ec2_eip
|
||||||
block:
|
block:
|
||||||
|
- name: set up aws connection info
|
||||||
- name: set up aws connection info
|
set_fact:
|
||||||
set_fact:
|
aws_connection_info: &aws_connection_info
|
||||||
aws_connection_info: &aws_connection_info
|
aws_access_key: "{{ aws_access_key }}"
|
||||||
aws_access_key: "{{ aws_access_key }}"
|
aws_secret_key: "{{ aws_secret_key }}"
|
||||||
aws_secret_key: "{{ aws_secret_key }}"
|
security_token: "{{ security_token }}"
|
||||||
security_token: "{{ security_token }}"
|
region: "{{ aws_region }}"
|
||||||
region: "{{ aws_region }}"
|
no_log: True
|
||||||
no_log: True
|
|
||||||
|
- name: Allocate a new eip - attempt reusing unallocated ones
|
||||||
- name: Allocate a new eip - attempt reusing unallocated ones
|
ec2_eip:
|
||||||
ec2_eip:
|
state: present
|
||||||
state: present
|
in_vpc: yes
|
||||||
in_vpc: yes
|
reuse_existing_ip_allowed: yes
|
||||||
reuse_existing_ip_allowed: yes
|
<<: *aws_connection_info
|
||||||
<<: *aws_connection_info
|
register: eip
|
||||||
register: eip
|
|
||||||
|
- assert:
|
||||||
- assert:
|
that:
|
||||||
that:
|
- eip is defined
|
||||||
- eip is defined
|
- eip.public_ip is defined and eip.public_ip != ""
|
||||||
- eip.public_ip is defined and eip.public_ip != ""
|
- eip.allocation_id is defined and eip.allocation_id != ""
|
||||||
- eip.allocation_id is defined and eip.allocation_id != ""
|
|
||||||
|
- name: Allocate a new eip
|
||||||
- name: Allocate a new eip
|
ec2_eip:
|
||||||
ec2_eip:
|
state: present
|
||||||
state: present
|
in_vpc: yes
|
||||||
in_vpc: yes
|
<<: *aws_connection_info
|
||||||
<<: *aws_connection_info
|
register: new_eip
|
||||||
register: new_eip
|
|
||||||
|
- assert:
|
||||||
- assert:
|
that:
|
||||||
that:
|
- new_eip is defined
|
||||||
- new_eip is defined
|
- new_eip is changed
|
||||||
- new_eip is changed
|
- new_eip.public_ip is defined and new_eip.public_ip != ""
|
||||||
- new_eip.public_ip is defined and new_eip.public_ip != ""
|
- new_eip.allocation_id is defined and new_eip.allocation_id != ""
|
||||||
- new_eip.allocation_id is defined and new_eip.allocation_id != ""
|
|
||||||
|
- name: Match an existing eip (changed == false)
|
||||||
- name: Match an existing eip (changed == false)
|
ec2_eip:
|
||||||
ec2_eip:
|
state: present
|
||||||
state: present
|
in_vpc: yes
|
||||||
in_vpc: yes
|
<<: *aws_connection_info
|
||||||
<<: *aws_connection_info
|
public_ip: "{{ eip.public_ip }}"
|
||||||
public_ip: "{{ eip.public_ip }}"
|
register: existing_eip
|
||||||
register: existing_eip
|
|
||||||
|
- assert:
|
||||||
- assert:
|
that:
|
||||||
that:
|
- existing_eip is defined
|
||||||
- existing_eip is defined
|
- existing_eip is not changed
|
||||||
- existing_eip is not changed
|
- existing_eip.public_ip is defined and existing_eip.public_ip != ""
|
||||||
- existing_eip.public_ip is defined and existing_eip.public_ip != ""
|
- existing_eip.allocation_id is defined and existing_eip.allocation_id != ""
|
||||||
- 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)
|
||||||
- name: attempt reusing an existing eip with a tag (or allocate a new one)
|
ec2_eip:
|
||||||
ec2_eip:
|
state: present
|
||||||
state: present
|
in_vpc: yes
|
||||||
in_vpc: yes
|
<<: *aws_connection_info
|
||||||
<<: *aws_connection_info
|
reuse_existing_ip_allowed: yes
|
||||||
reuse_existing_ip_allowed: yes
|
tag_name: Team
|
||||||
tag_name: Team
|
register: tagged_eip
|
||||||
register: tagged_eip
|
|
||||||
|
- assert:
|
||||||
- assert:
|
that:
|
||||||
that:
|
- tagged_eip is defined
|
||||||
- tagged_eip is defined
|
- tagged_eip.public_ip is defined and tagged_eip.public_ip != ""
|
||||||
- tagged_eip.public_ip is defined and tagged_eip.public_ip != ""
|
- tagged_eip.allocation_id is defined and tagged_eip.allocation_id != ""
|
||||||
- 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)
|
||||||
- name: attempt reusing an existing eip with a tag and it's value (or allocate a new one)
|
ec2_eip:
|
||||||
ec2_eip:
|
state: present
|
||||||
state: present
|
in_vpc: yes
|
||||||
in_vpc: yes
|
<<: *aws_connection_info
|
||||||
<<: *aws_connection_info
|
public_ip: "{{ eip.public_ip }}"
|
||||||
public_ip: "{{ eip.public_ip }}"
|
reuse_existing_ip_allowed: yes
|
||||||
reuse_existing_ip_allowed: yes
|
tag_name: Team
|
||||||
tag_name: Team
|
tag_value: Backend
|
||||||
tag_value: Backend
|
register: backend_eip
|
||||||
register: backend_eip
|
|
||||||
|
- assert:
|
||||||
- assert:
|
that:
|
||||||
that:
|
- backend_eip is defined
|
||||||
- backend_eip is defined
|
- backend_eip.public_ip is defined and backend_eip.public_ip != ""
|
||||||
- backend_eip.public_ip is defined and backend_eip.public_ip != ""
|
- backend_eip.allocation_id is defined and backend_eip.allocation_id != ""
|
||||||
- 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)
|
||||||
- name: attempt reusing an existing eip with a tag and it's value (or allocate a new one from pool)
|
ec2_eip:
|
||||||
ec2_eip:
|
state: present
|
||||||
state: present
|
in_vpc: yes
|
||||||
in_vpc: yes
|
<<: *aws_connection_info
|
||||||
<<: *aws_connection_info
|
reuse_existing_ip_allowed: yes
|
||||||
reuse_existing_ip_allowed: yes
|
tag_name: Team
|
||||||
tag_name: Team
|
tag_value: Backend
|
||||||
tag_value: Backend
|
public_ipv4_pool: amazon
|
||||||
public_ipv4_pool: amazon
|
register: amazon_eip
|
||||||
register: amazon_eip
|
|
||||||
|
- assert:
|
||||||
- assert:
|
that:
|
||||||
that:
|
- amazon_eip is defined
|
||||||
- amazon_eip is defined
|
- amazon_eip.public_ip is defined and amazon_eip.public_ip != ""
|
||||||
- amazon_eip.public_ip is defined and amazon_eip.public_ip != ""
|
- amazon_eip.allocation_id is defined and amazon_eip.allocation_id != ""
|
||||||
- amazon_eip.allocation_id is defined and amazon_eip.allocation_id != ""
|
|
||||||
|
- name: allocate a new eip from a pool
|
||||||
- name: allocate a new eip from a pool
|
ec2_eip:
|
||||||
ec2_eip:
|
state: present
|
||||||
state: present
|
in_vpc: yes
|
||||||
in_vpc: yes
|
<<: *aws_connection_info
|
||||||
<<: *aws_connection_info
|
public_ipv4_pool: amazon
|
||||||
public_ipv4_pool: amazon
|
register: pool_eip
|
||||||
register: pool_eip
|
|
||||||
|
- assert:
|
||||||
- assert:
|
that:
|
||||||
that:
|
- pool_eip is defined
|
||||||
- pool_eip is defined
|
- pool_eip is changed
|
||||||
- pool_eip is changed
|
- pool_eip.public_ip is defined and pool_eip.public_ip != ""
|
||||||
- pool_eip.public_ip is defined and pool_eip.public_ip != ""
|
- pool_eip.allocation_id is defined and pool_eip.allocation_id != ""
|
||||||
- pool_eip.allocation_id is defined and pool_eip.allocation_id != ""
|
always:
|
||||||
|
- debug:
|
||||||
always:
|
msg: "{{ item }}"
|
||||||
- debug: msg="{{ item }}"
|
when: item is defined and item.public_ip is defined and item.allocation_id is defined
|
||||||
when: item is defined and item.public_ip is defined and item.allocation_id is defined
|
loop:
|
||||||
loop:
|
- eip
|
||||||
- eip
|
- new_eip
|
||||||
- new_eip
|
- pool_eip
|
||||||
- pool_eip
|
- tagged_eip
|
||||||
- tagged_eip
|
- backend_eip
|
||||||
- backend_eip
|
- amazon_eip
|
||||||
- amazon_eip
|
- name: Cleanup newly allocated eip
|
||||||
- name: Cleanup newly allocated eip
|
ec2_eip:
|
||||||
ec2_eip:
|
state: absent
|
||||||
state: absent
|
public_ip: "{{ item.public_ip }}"
|
||||||
public_ip: "{{ item.public_ip }}"
|
in_vpc: yes
|
||||||
in_vpc: yes
|
<<: *aws_connection_info
|
||||||
<<: *aws_connection_info
|
when: item is defined and item is changed and item.public_ip is defined and item.public_ip != ""
|
||||||
when: item is defined and item is changed and item.public_ip is defined and item.public_ip != ""
|
loop:
|
||||||
loop:
|
- "{{ eip }}"
|
||||||
- "{{ eip }}"
|
- "{{ new_eip }}"
|
||||||
- "{{ new_eip }}"
|
- "{{ pool_eip }}"
|
||||||
- "{{ pool_eip }}"
|
- "{{ tagged_eip }}"
|
||||||
- "{{ tagged_eip }}"
|
- "{{ backend_eip }}"
|
||||||
- "{{ backend_eip }}"
|
- "{{ amazon_eip }}"
|
||||||
- "{{ amazon_eip }}"
|
|
||||||
...
|
...
|
Loading…
Reference in New Issue