[cloud] Improve results from ecs_taskdefinition_facts (#34337)
ecs_taskdefinition_facts should not populate ansible_facts with so much information. Better to just return the contents of the dict directly. Reduce line lengths, use AnsibleAWSModule, don't reimplement camel_dict_to_snake_dict.
This commit is contained in:
parent
2fac647955
commit
56196e66bf
2 changed files with 27 additions and 25 deletions
|
@ -15,7 +15,8 @@ DOCUMENTATION = '''
|
||||||
module: ecs_taskdefinition_facts
|
module: ecs_taskdefinition_facts
|
||||||
short_description: describe a task definition in ecs
|
short_description: describe a task definition in ecs
|
||||||
notes:
|
notes:
|
||||||
- for details of the parameters and returns see U(http://boto3.readthedocs.io/en/latest/reference/services/ecs.html#ECS.Client.describe_task_definition)
|
- for details of the parameters and returns see
|
||||||
|
U(http://boto3.readthedocs.io/en/latest/reference/services/ecs.html#ECS.Client.describe_task_definition)
|
||||||
description:
|
description:
|
||||||
- Describes a task definition in ecs.
|
- Describes a task definition in ecs.
|
||||||
version_added: "2.5"
|
version_added: "2.5"
|
||||||
|
@ -123,7 +124,8 @@ container_definitions:
|
||||||
returned: when present
|
returned: when present
|
||||||
type: string
|
type: string
|
||||||
readOnly:
|
readOnly:
|
||||||
description: If this value is true , the container has read-only access to the volume. If this value is false , then the container can write to the volume.
|
description: If this value is true , the container has read-only access to the volume.
|
||||||
|
If this value is false , then the container can write to the volume.
|
||||||
returned: when present
|
returned: when present
|
||||||
type: bool
|
type: bool
|
||||||
volumesFrom:
|
volumesFrom:
|
||||||
|
@ -136,7 +138,8 @@ container_definitions:
|
||||||
returned: when present
|
returned: when present
|
||||||
type: string
|
type: string
|
||||||
readOnly:
|
readOnly:
|
||||||
description: If this value is true , the container has read-only access to the volume. If this value is false , then the container can write to the volume.
|
description: If this value is true , the container has read-only access to the volume.
|
||||||
|
If this value is false , then the container can write to the volume.
|
||||||
returned: when present
|
returned: when present
|
||||||
type: bool
|
type: bool
|
||||||
hostname:
|
hostname:
|
||||||
|
@ -156,7 +159,8 @@ container_definitions:
|
||||||
returned: when present
|
returned: when present
|
||||||
type: bool
|
type: bool
|
||||||
privileged:
|
privileged:
|
||||||
description: When this parameter is true, the container is given elevated privileges on the host container instance (similar to the root user).
|
description: When this parameter is true, the container is given elevated
|
||||||
|
privileges on the host container instance (similar to the root user).
|
||||||
returned: when present
|
returned: when present
|
||||||
type: bool
|
type: bool
|
||||||
readonlyRootFilesystem:
|
readonlyRootFilesystem:
|
||||||
|
@ -248,7 +252,8 @@ volumes:
|
||||||
returned: when present
|
returned: when present
|
||||||
type: string
|
type: string
|
||||||
host:
|
host:
|
||||||
description: The contents of the host parameter determine whether your data volume persists on the host container instance and where it is stored.
|
description: The contents of the host parameter determine whether your data volume
|
||||||
|
persists on the host container instance and where it is stored.
|
||||||
returned: when present
|
returned: when present
|
||||||
type: bool
|
type: bool
|
||||||
source_path:
|
source_path:
|
||||||
|
@ -293,21 +298,15 @@ placement_constraints:
|
||||||
description: A cluster query language expression to apply to the constraint.
|
description: A cluster query language expression to apply to the constraint.
|
||||||
returned: when present
|
returned: when present
|
||||||
type: string
|
type: string
|
||||||
''' # NOQA
|
'''
|
||||||
|
|
||||||
try:
|
from ansible.module_utils.aws.core import AnsibleAWSModule
|
||||||
import boto3
|
from ansible.module_utils.ec2 import camel_dict_to_snake_dict, boto3_conn, ec2_argument_spec, get_aws_connection_info
|
||||||
HAS_BOTO3 = True
|
|
||||||
except ImportError:
|
|
||||||
HAS_BOTO3 = False
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
|
||||||
from ansible.module_utils.ec2 import _camel_to_snake, camel_dict_to_snake_dict, boto3_conn, ec2_argument_spec, get_aws_connection_info
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import botocore
|
import botocore
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass # will be detected by imported HAS_BOTO3
|
pass # will be detected by imported AnsibleAWSModule
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -316,22 +315,18 @@ def main():
|
||||||
task_definition=dict(required=True, type='str')
|
task_definition=dict(required=True, type='str')
|
||||||
))
|
))
|
||||||
|
|
||||||
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)
|
||||||
|
|
||||||
if not HAS_BOTO3:
|
|
||||||
module.fail_json(msg='boto3 is required.')
|
|
||||||
|
|
||||||
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
|
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
|
||||||
ecs = boto3_conn(module, conn_type='client', resource='ecs',
|
ecs = boto3_conn(module, conn_type='client', resource='ecs',
|
||||||
region=region, endpoint=ec2_url, **aws_connect_kwargs)
|
region=region, endpoint=ec2_url, **aws_connect_kwargs)
|
||||||
|
|
||||||
|
try:
|
||||||
ecs_td = ecs.describe_task_definition(taskDefinition=module.params['task_definition'])['taskDefinition']
|
ecs_td = ecs.describe_task_definition(taskDefinition=module.params['task_definition'])['taskDefinition']
|
||||||
ecs_td_snake = {}
|
except botocore.exceptions.ClientError:
|
||||||
for k, v in ecs_td.items():
|
ecs_td = {}
|
||||||
ecs_td_snake[_camel_to_snake(k)] = v
|
|
||||||
|
|
||||||
ecs_td_facts_result = dict(changed=False, ansible_facts=ecs_td_snake)
|
module.exit_json(changed=False, **camel_dict_to_snake_dict(ecs_td))
|
||||||
module.exit_json(**ecs_td_facts_result)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -250,6 +250,8 @@
|
||||||
that:
|
that:
|
||||||
- update_ecs_service.failed
|
- update_ecs_service.failed
|
||||||
- "'msg' in update_ecs_service"
|
- "'msg' in update_ecs_service"
|
||||||
|
# FIXME: fixed in #32876
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
- name: obtain ECS service facts
|
- name: obtain ECS service facts
|
||||||
ecs_service_facts:
|
ecs_service_facts:
|
||||||
|
@ -257,6 +259,11 @@
|
||||||
cluster: "{{ ecs_cluster_name }}"
|
cluster: "{{ ecs_cluster_name }}"
|
||||||
<<: *aws_connection_info
|
<<: *aws_connection_info
|
||||||
|
|
||||||
|
- name: attempt to get facts from missing task definition
|
||||||
|
ecs_taskdefinition_facts:
|
||||||
|
task_definition: "{{ ecs_task_name }}-vpc:{{ ecs_task_definition.taskdefinition.revision + 1}}"
|
||||||
|
<<: *aws_connection_info
|
||||||
|
|
||||||
always:
|
always:
|
||||||
|
|
||||||
# TEAR DOWN: snapshot, ec2 instance, ec2 key pair, security group, vpc
|
# TEAR DOWN: snapshot, ec2 instance, ec2 key pair, security group, vpc
|
||||||
|
|
Loading…
Reference in a new issue