Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Dec 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 30 additions & 7 deletions lib/ansible/modules/cloud/amazon/ecs_taskdefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
- A list of containers definitions
required: False
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:
description:
- A list of names of volumes to be attached
Expand Down Expand Up @@ -137,7 +149,7 @@ def describe_task(self, task_name):
except botocore.exceptions.ClientError:
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 = []

# Ensures the number parameters are int as required by boto
Expand All @@ -154,8 +166,15 @@ def register_task(self, family, container_definitions, volumes):

validated_containers.append(container)

response = self.ecs.register_task_definition(family=family,
containerDefinitions=validated_containers, volumes=volumes)
try:
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']

def describe_task_definitions(self, family):
Expand Down Expand Up @@ -189,6 +208,7 @@ def deregister_task(self, taskArn):
response = self.ecs.deregister_task_definition(taskDefinition=taskArn)
return response['taskDefinition']


def main():

argument_spec = ec2_argument_spec()
Expand All @@ -198,8 +218,9 @@ def main():
family=dict(required=False, type='str'),
revision=dict(required=False, type='int'),
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)

Expand Down Expand Up @@ -325,7 +346,10 @@ def _task_definition_matches(requested_volumes, requested_containers, existing_t
# Doesn't exist. create it.
volumes = module.params.get('volumes', []) or []
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

elif module.params['state'] == 'absent':
Expand Down Expand Up @@ -355,6 +379,5 @@ def _task_definition_matches(requested_volumes, requested_containers, existing_t

module.exit_json(**results)


if __name__ == '__main__':
main()