Repository: ansible/ansible

Issue:
Start of aws best practices docs
Disclaimer: I think the formatting is ok here (famous last words) 

This is a PR for a docs page which discusses some best practices and how-to for using Ansible with AWS. This should be a living document, we should encourage folks to add to this and share how they are using Ansible with AWS / a-n-other cloud (since majority of it is generic). I still need to add details on usage / use case for each module. I propose adding this information later once we find a place for this base document.



Discussion:
Going to take a look at this hopefully Monday, great to see this -- lots of interest from folks in having this kind of writeup, thanks!

Thanks @mpdehaan.  Long term I think much of this (and more) can be generic across "The Cloud", since many of the same concepts apply.

Different modules for different clouds, I can see it being split up, but yeah, some of these concepts... there are probably chapters and subchapters at some point in the distant future.   Looking at this now...

Ok, tweaked a few things -- using 1.2 syntax, added some text and so forth.

If you want to add things about the S3 module and so on that would be awesome.  I am also thinking we might want to explain the inventory module a bit more on that page, I don't know.

Thanks!


Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/ecs_taskdefinition.py b/lib/ansible/modules/cloud/amazon/ecs_taskdefinition.py
--- a/lib/ansible/modules/cloud/amazon/ecs_taskdefinition.py
+++ b/lib/ansible/modules/cloud/amazon/ecs_taskdefinition.py
@@ -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
@@ -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
@@ -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):
@@ -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()
@@ -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)
 
@@ -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':
@@ -355,6 +379,5 @@ def _task_definition_matches(requested_volumes, requested_containers, existing_t
 
     module.exit_json(**results)
 
-
 if __name__ == '__main__':
     main()


Test patch: