community.aws
community.aws copied to clipboard
Add task to get a list of all ECS clusters
Summary
We want to control our AWS ECS services, for example, to restart all services in all accounts when Fargate is updated. For this reason, we run our playbooks against many clusters and we want the cluster_name to be discovered. However, all of the community.aws ECS modules either require a cluster name variable or add one with a default value of "default". I could not find a way to list the ECS cluster names, ie. the equivalent of "aws ecs list-clusters".
Issue Type
Feature Idea
Component Name
community.aws.ecs_cluster
Additional Information
This could be implemented similar to the way services are handled in community.aws.ecs_service_info - if no service_name is given, all services are queried.
Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
Two ideas about it
- rework
community.aws.ecs_service_info
If the cluster
parameter is not given, it must return all services of all clusters.
I am not sure atm. Maybe it's just a bug and should work like that way already: https://github.com/ansible-collections/community.aws/blob/main/plugins/modules/ecs_service_info.py#L218
- new module
community.aws.ecs_cluster_info
A new module that just returns all existing clusters.
Just tested it, when running without the cluster parameter:
- name: "List all services in cluster {{ ecs_cluster }}"
community.aws.ecs_service_info:
# cluster: "{{ ecs_cluster }}"
region: "{{ selected_region }}"
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
aws_session_token: "{{ aws_session_token }}"
register: ecs_services
...the result is a ClusterNotFound failure, with the following invocation parameters:
"invocation": {
"module_args": {
"access_key": "...",
"aws_access_key": "...",
"aws_ca_bundle": null,
"aws_config": null,
"aws_secret_key": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"aws_session_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"cluster": null,
"debug_botocore_endpoint_logs": false,
"details": false,
"endpoint_url": null,
"events": true,
"profile": null,
"region": "eu-west-1",
"secret_key": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"service": null,
"session_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"validate_certs": true
}
},