mirror of https://github.com/ansible/ansible.git
[aws]Add VPC configuration to ECS modules (#34381)
Enable awsvpc network mode for ECS services and tasks and their underlying task definitions Improve test suite to thoroughly test the changes Use runme.sh technique to run old and new versions of botocore to ensure that the modules work with older botocore and older network modes and fail gracefully if awsvpc network mode is used with older botocorepull/39335/head
parent
58bf4ae611
commit
12f2b9506d
@ -0,0 +1,5 @@
|
||||
- hosts: localhost
|
||||
connection: local
|
||||
|
||||
roles:
|
||||
- ecs_cluster
|
@ -0,0 +1,146 @@
|
||||
- hosts: localhost
|
||||
connection: local
|
||||
|
||||
tasks:
|
||||
- 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: create ecs cluster
|
||||
ecs_cluster:
|
||||
name: "{{ resource_prefix }}"
|
||||
state: present
|
||||
<<: *aws_connection_info
|
||||
|
||||
- name: create ecs_taskdefinition with bridged network
|
||||
ecs_taskdefinition:
|
||||
containers:
|
||||
- name: my_container
|
||||
image: ubuntu
|
||||
memory: 128
|
||||
family: "{{ resource_prefix }}"
|
||||
state: present
|
||||
network_mode: bridge
|
||||
<<: *aws_connection_info
|
||||
register: ecs_taskdefinition_creation
|
||||
|
||||
- name: create ecs_taskdefinition with awsvpc network
|
||||
ecs_taskdefinition:
|
||||
containers:
|
||||
- name: my_container
|
||||
image: ubuntu
|
||||
memory: 128
|
||||
family: "{{ resource_prefix }}-vpc"
|
||||
state: present
|
||||
network_mode: awsvpc
|
||||
<<: *aws_connection_info
|
||||
register: ecs_taskdefinition_creation_vpc
|
||||
|
||||
- name: ecs_taskdefinition works fine even when older botocore is used
|
||||
assert:
|
||||
that:
|
||||
- ecs_taskdefinition_creation_vpc.changed
|
||||
|
||||
- name: create ecs_service using bridged network
|
||||
ecs_service:
|
||||
name: "{{ resource_prefix }}"
|
||||
cluster: "{{ resource_prefix }}"
|
||||
task_definition: "{{ resource_prefix }}"
|
||||
desired_count: 1
|
||||
state: present
|
||||
<<: *aws_connection_info
|
||||
register: ecs_service_creation
|
||||
|
||||
- name: create ecs_service using awsvpc network_configuration
|
||||
ecs_service:
|
||||
name: "{{ resource_prefix }}-vpc"
|
||||
cluster: "{{ resource_prefix }}"
|
||||
task_definition: "{{ resource_prefix }}"
|
||||
desired_count: 1
|
||||
network_configuration:
|
||||
subnets:
|
||||
- subnet-abcd1234
|
||||
groups:
|
||||
- sg-abcd1234
|
||||
state: present
|
||||
<<: *aws_connection_info
|
||||
register: ecs_service_creation_vpc
|
||||
ignore_errors: yes
|
||||
|
||||
- name: check that graceful failure message is returned from ecs_service
|
||||
assert:
|
||||
that:
|
||||
- ecs_service_creation_vpc.failed
|
||||
- 'ecs_service_creation_vpc.msg == "botocore needs to be version 1.7.44 or higher to use network configuration"'
|
||||
|
||||
- name: create ecs_task using awsvpc network_configuration
|
||||
ecs_task:
|
||||
cluster: "{{ resource_prefix }}-vpc"
|
||||
task_definition: "{{ resource_prefix }}"
|
||||
operation: run
|
||||
count: 1
|
||||
started_by: me
|
||||
network_configuration:
|
||||
subnets:
|
||||
- subnet-abcd1234
|
||||
groups:
|
||||
- sg-abcd1234
|
||||
<<: *aws_connection_info
|
||||
register: ecs_task_creation_vpc
|
||||
ignore_errors: yes
|
||||
|
||||
- name: check that graceful failure message is returned from ecs_task
|
||||
assert:
|
||||
that:
|
||||
- ecs_task_creation_vpc.failed
|
||||
- 'ecs_task_creation_vpc.msg == "botocore needs to be version 1.7.44 or higher to use network configuration"'
|
||||
|
||||
always:
|
||||
- name: scale down ecs service
|
||||
ecs_service:
|
||||
name: "{{ resource_prefix }}"
|
||||
cluster: "{{ resource_prefix }}"
|
||||
task_definition: "{{ resource_prefix }}"
|
||||
desired_count: 0
|
||||
state: present
|
||||
<<: *aws_connection_info
|
||||
ignore_errors: yes
|
||||
|
||||
- name: pause to wait for scale down
|
||||
pause:
|
||||
seconds: 30
|
||||
|
||||
- name: remove ecs service
|
||||
ecs_service:
|
||||
name: "{{ resource_prefix }}"
|
||||
cluster: "{{ resource_prefix }}"
|
||||
task_definition: "{{ resource_prefix }}"
|
||||
desired_count: 1
|
||||
state: absent
|
||||
<<: *aws_connection_info
|
||||
ignore_errors: yes
|
||||
|
||||
- name: remove ecs task definition
|
||||
ecs_taskdefinition:
|
||||
containers:
|
||||
- name: my_container
|
||||
image: ubuntu
|
||||
memory: 128
|
||||
family: "{{ resource_prefix }}"
|
||||
revision: "{{ ecs_taskdefinition_creation.taskdefinition.revision }}"
|
||||
state: absent
|
||||
<<: *aws_connection_info
|
||||
ignore_errors: yes
|
||||
|
||||
- name: remove ecs cluster
|
||||
ecs_cluster:
|
||||
name: "{{ resource_prefix }}"
|
||||
state: absent
|
||||
<<: *aws_connection_info
|
||||
ignore_errors: yes
|
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# We don't set -u here, due to pypa/virtualenv#150
|
||||
set -ex
|
||||
|
||||
MYTMPDIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
|
||||
|
||||
trap 'rm -rf "${MYTMPDIR}"' EXIT
|
||||
|
||||
# This is needed for the ubuntu1604py3 tests
|
||||
# Ubuntu patches virtualenv to make the default python2
|
||||
# but for the python3 tests we need virtualenv to use python3
|
||||
PYTHON=${ANSIBLE_TEST_PYTHON_INTERPRETER:-python}
|
||||
|
||||
# Test graceful failure for older versions of botocore
|
||||
virtualenv --system-site-packages --python "${PYTHON}" "${MYTMPDIR}/botocore-1.7.40"
|
||||
source "${MYTMPDIR}/botocore-1.7.40/bin/activate"
|
||||
$PYTHON -m pip install 'botocore<=1.7.40' boto3
|
||||
ansible-playbook -i ../../inventory -e @../../integration_config.yml -e @../../cloud-config-aws.yml -v playbooks/network_fail.yml "$@"
|
||||
|
||||
# Run full test suite
|
||||
virtualenv --system-site-packages --python "${PYTHON}" "${MYTMPDIR}/botocore-recent"
|
||||
source "${MYTMPDIR}/botocore-recent/bin/activate"
|
||||
$PYTHON -m pip install 'botocore>=1.8.0' boto3
|
||||
ansible-playbook -i ../../inventory -e @../../integration_config.yml -e @../../cloud-config-aws.yml -v playbooks/full_test.yml "$@"
|
Loading…
Reference in New Issue