1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add new parameters to taskdefinition module - network_mode and task_r… (#19493)

* Add new parameters to taskdefinition module - network_mode and task_role_arn

* Add version_added field for doco

* Change version_added parameter to 2.3
This commit is contained in:
Rob 2016-12-20 05:16:35 +11:00 committed by John R Barker
parent a080d44a47
commit cfa8ce767b

View file

@ -51,6 +51,18 @@ options:
- A list of containers definitions - A list of containers definitions
required: False required: False
type: list of dicts with container definitions type: list of dicts with container definitions
network_mode:
description:
- The Docker networking mode to use for the containers in the task.
required: false
default: bridge
choices: [ 'bridge', 'host', 'none' ]
version_added: 2.3
task_role_arn:
description:
- The Amazon Resource Name (ARN) of the IAM role that containers in this task can assume. All containers in this task are granted the permissions that are specified in this role.
required: false
version_added: 2.3
volumes: volumes:
description: description:
- A list of names of volumes to be attached - A list of names of volumes to be attached
@ -137,7 +149,7 @@ class EcsTaskManager:
except botocore.exceptions.ClientError: except botocore.exceptions.ClientError:
return None return None
def register_task(self, family, container_definitions, volumes): def register_task(self, family, task_role_arn, network_mode, container_definitions, volumes):
validated_containers = [] validated_containers = []
# Ensures the number parameters are int as required by boto # Ensures the number parameters are int as required by boto
@ -154,8 +166,15 @@ class EcsTaskManager:
validated_containers.append(container) validated_containers.append(container)
response = self.ecs.register_task_definition(family=family, try:
containerDefinitions=validated_containers, volumes=volumes) response = self.ecs.register_task_definition(family=family,
taskRoleArn=task_role_arn,
networkMode=network_mode,
containerDefinitions=container_definitions,
volumes=volumes)
except botocore.exceptions.ClientError as e:
self.module.fail_json(msg=e.message, **camel_dict_to_snake_dict(e.response))
return response['taskDefinition'] return response['taskDefinition']
def describe_task_definitions(self, family): def describe_task_definitions(self, family):
@ -189,6 +208,7 @@ class EcsTaskManager:
response = self.ecs.deregister_task_definition(taskDefinition=taskArn) response = self.ecs.deregister_task_definition(taskDefinition=taskArn)
return response['taskDefinition'] return response['taskDefinition']
def main(): def main():
argument_spec = ec2_argument_spec() argument_spec = ec2_argument_spec()
@ -198,8 +218,9 @@ def main():
family=dict(required=False, type='str'), family=dict(required=False, type='str'),
revision=dict(required=False, type='int'), revision=dict(required=False, type='int'),
containers=dict(required=False, type='list'), containers=dict(required=False, type='list'),
volumes=dict(required=False, type='list') network_mode=dict(required=False, default='bridge', choices=['bridge', 'host', 'none'], type='str'),
)) task_role_arn=dict(required=False, default='', type='str'),
volumes=dict(required=False, type='list')))
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
@ -325,7 +346,10 @@ def main():
# Doesn't exist. create it. # Doesn't exist. create it.
volumes = module.params.get('volumes', []) or [] volumes = module.params.get('volumes', []) or []
results['taskdefinition'] = task_mgr.register_task(module.params['family'], results['taskdefinition'] = task_mgr.register_task(module.params['family'],
module.params['containers'], volumes) module.params['task_role_arn'],
module.params['network_mode'],
module.params['containers'],
volumes)
results['changed'] = True results['changed'] = True
elif module.params['state'] == 'absent': elif module.params['state'] == 'absent':
@ -355,6 +379,5 @@ def main():
module.exit_json(**results) module.exit_json(**results)
if __name__ == '__main__': if __name__ == '__main__':
main() main()