We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
ec2_lc_find not returning AssociatePublicIpAddress
##### ISSUE TYPE
Bug Report

##### COMPONENT NAME
ec2_lc_find

##### ANSIBLE VERSION
```
ansible 2.2.0.0
  config file = /home/centos/ansiblebase/ansible.cfg
  configured module search path = Default w/o overrides
```

##### CONFIGURATION
No significant changes

##### OS / ENVIRONMENT
Started with Ansible Tower 3.0.3 on CentOS 7 x86_64
Did a yum update on ansible to 2.2.
Did pip install boto3.

##### SUMMARY
Running ec2_lc_find fails with a missing key for AssociatePublicIpAddress

##### STEPS TO REPRODUCE
```
- ec2_lc_find:
    region: "{{ region }}"
    name_regex: lc_name-*"
    sort_order: ascending
    limit: 3
  register: old_lc_result
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
Correctly returns load configurations matching regex.

##### ACTUAL RESULTS
```
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'AssociatePublicIpAddress'
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_dJ3ho0/ansible_module_ec2_lc_find.py\", line 225, in <module>\n    main()\n  File \"/tmp/ansible_dJ3ho0/ansible_module_ec2_lc_find.py\", line 217, in main\n    find_launch_configs(client, module)\n  File \"/tmp/ansible_dJ3ho0/ansible_module_ec2_lc_find.py\", line 187, in find_launch_configs\n    'associate_public_address': lc['AssociatePublicIpAddress'],\nKeyError: 'AssociatePublicIpAddress'\n", "module_stdout": "", "msg": "MODULE FAILURE"}
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `cloud/amazon/ec2_lc_find.py`
Content:
```
1 #!/usr/bin/python
2 # encoding: utf-8
3 
4 # (c) 2015, Jose Armesto <jose@armesto.net>
5 #
6 # This file is part of Ansible
7 #
8 # This module is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This software is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this software.  If not, see <http://www.gnu.org/licenses/>.
20 
21 DOCUMENTATION = """
22 ---
23 module: ec2_lc_find
24 short_description: Find AWS Autoscaling Launch Configurations
25 description:
26   - Returns list of matching Launch Configurations for a given name, along with other useful information
27   - Results can be sorted and sliced
28   - It depends on boto
29   - Based on the work by Tom Bamford (https://github.com/tombamford)
30 
31 version_added: "2.2"
32 author: "Jose Armesto (@fiunchinho)"
33 options:
34   region:
35     description:
36       - The AWS region to use.
37     required: true
38     aliases: ['aws_region', 'ec2_region']
39   name_regex:
40     description:
41       - A Launch Configuration to match
42       - It'll be compiled as regex
43     required: True
44   sort_order:
45     description:
46       - Order in which to sort results.
47     choices: ['ascending', 'descending']
48     default: 'ascending'
49     required: false
50   limit:
51     description:
52       - How many results to show.
53       - Corresponds to Python slice notation like list[:limit].
54     default: null
55     required: false
56 requirements:
57   - "python >= 2.6"
58   - boto3
59 """
60 
61 EXAMPLES = '''
62 # Note: These examples do not set authentication details, see the AWS Guide for details.
63 
64 # Search for the Launch Configurations that start with "app"
65 - ec2_lc_find:
66     name_regex: app.*
67     sort_order: descending
68     limit: 2
69 '''
70 
71 RETURN = '''
72 image_id:
73     description: AMI id
74     returned: when Launch Configuration was found
75     type: string
76     sample: "ami-0d75df7e"
77 user_data:
78     description: User data used to start instance
79     returned: when Launch Configuration was found
80     type: string
81     user_data: "ZXhwb3J0IENMT1VE"
82 name:
83     description: Name of the AMI
84     returned: when Launch Configuration was found
85     type: string
86     sample: "myapp-v123"
87 arn:
88     description: Name of the AMI
89     returned: when Launch Configuration was found
90     type: string
91     sample: "arn:aws:autoscaling:eu-west-1:12345:launchConfiguration:d82f050e-e315:launchConfigurationName/yourproject"
92 instance_type:
93     description: Type of ec2 instance
94     returned: when Launch Configuration was found
95     type: string
96     sample: "t2.small"
97 created_time:
98     description: When it was created
99     returned: when Launch Configuration was found
100     type: string
101     sample: "2016-06-29T14:59:22.222000+00:00"
102 ebs_optimized:
103     description: Launch Configuration EBS optimized property
104     returned: when Launch Configuration was found
105     type: boolean
106     sample: False
107 instance_monitoring:
108     description: Launch Configuration instance monitoring property
109     returned: when Launch Configuration was found
110     type: string
111     sample: {"Enabled": false}
112 classic_link_vpc_security_groups:
113     description: Launch Configuration classic link vpc security groups property
114     returned: when Launch Configuration was found
115     type: list
116     sample: []
117 block_device_mappings:
118     description: Launch Configuration block device mappings property
119     returned: when Launch Configuration was found
120     type: list
121     sample: []
122 keyname:
123     description: Launch Configuration ssh key
124     returned: when Launch Configuration was found
125     type: string
126     sample: mykey
127 security_groups:
128     description: Launch Configuration security groups
129     returned: when Launch Configuration was found
130     type: list
131     sample: []
132 kernel_id:
133     description: Launch Configuration kernel to use
134     returned: when Launch Configuration was found
135     type: string
136     sample: ''
137 ram_disk_id:
138     description: Launch Configuration ram disk property
139     returned: when Launch Configuration was found
140     type: string
141     sample: ''
142 associate_public_address:
143     description: Assign public address or not
144     returned: when Launch Configuration was found
145     type: boolean
146     sample: True
147 ...
148 '''
149 
150 
151 def find_launch_configs(client, module):
152     name_regex = module.params.get('name_regex')
153     sort_order = module.params.get('sort_order')
154     limit = module.params.get('limit')
155 
156     paginator = client.get_paginator('describe_launch_configurations')
157 
158     response_iterator = paginator.paginate(
159         PaginationConfig={
160             'MaxItems': 1000,
161             'PageSize': 100
162         }
163     )
164 
165     results = []
166 
167     for response in response_iterator:
168         response['LaunchConfigurations'] = filter(lambda lc: re.compile(name_regex).match(lc['LaunchConfigurationName']),
169                                                   response['LaunchConfigurations'])
170 
171         for lc in response['LaunchConfigurations']:
172             data = {
173                 'name': lc['LaunchConfigurationName'],
174                 'arn': lc['LaunchConfigurationARN'],
175                 'created_time': lc['CreatedTime'],
176                 'user_data': lc['UserData'],
177                 'instance_type': lc['InstanceType'],
178                 'image_id': lc['ImageId'],
179                 'ebs_optimized': lc['EbsOptimized'],
180                 'instance_monitoring': lc['InstanceMonitoring'],
181                 'classic_link_vpc_security_groups': lc['ClassicLinkVPCSecurityGroups'],
182                 'block_device_mappings': lc['BlockDeviceMappings'],
183                 'keyname': lc['KeyName'],
184                 'security_groups': lc['SecurityGroups'],
185                 'kernel_id': lc['KernelId'],
186                 'ram_disk_id': lc['RamdiskId'],
187                 'associate_public_address': lc['AssociatePublicIpAddress'],
188             }
189 
190             results.append(data)
191 
192     results.sort(key=lambda e: e['name'], reverse=(sort_order == 'descending'))
193 
194     if limit:
195         results = results[:int(limit)]
196 
197     module.exit_json(changed=False, results=results)
198 
199 
200 def main():
201     argument_spec = ec2_argument_spec()
202     argument_spec.update(dict(
203         region=dict(required=True, aliases=['aws_region', 'ec2_region']),
204         name_regex=dict(required=True),
205         sort_order=dict(required=False, default='ascending', choices=['ascending', 'descending']),
206         limit=dict(required=False, type='int'),
207     )
208     )
209 
210     module = AnsibleModule(
211         argument_spec=argument_spec,
212     )
213 
214     region, ec2_url, aws_connect_params = get_aws_connection_info(module, True)
215 
216     client = boto3_conn(module=module, conn_type='client', resource='autoscaling', region=region, **aws_connect_params)
217     find_launch_configs(client, module)
218 
219 
220 # import module snippets
221 from ansible.module_utils.basic import *
222 from ansible.module_utils.ec2 import *
223 
224 if __name__ == '__main__':
225     main()
226
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/cloud/amazon/ec2_lc_find.py b/cloud/amazon/ec2_lc_find.py
--- a/cloud/amazon/ec2_lc_find.py
+++ b/cloud/amazon/ec2_lc_find.py
@@ -184,7 +184,7 @@
                 'security_groups': lc['SecurityGroups'],
                 'kernel_id': lc['KernelId'],
                 'ram_disk_id': lc['RamdiskId'],
-                'associate_public_address': lc['AssociatePublicIpAddress'],
+                'associate_public_address': lc.get('AssociatePublicIpAddress', False),
             }
 
             results.append(data)

{"golden_diff": "diff --git a/cloud/amazon/ec2_lc_find.py b/cloud/amazon/ec2_lc_find.py\n--- a/cloud/amazon/ec2_lc_find.py\n+++ b/cloud/amazon/ec2_lc_find.py\n@@ -184,7 +184,7 @@\n                 'security_groups': lc['SecurityGroups'],\n                 'kernel_id': lc['KernelId'],\n                 'ram_disk_id': lc['RamdiskId'],\n-                'associate_public_address': lc['AssociatePublicIpAddress'],\n+                'associate_public_address': lc.get('AssociatePublicIpAddress', False),\n             }\n \n             results.append(data)\n", "issue": "ec2_lc_find not returning AssociatePublicIpAddress\n##### ISSUE TYPE\r\nBug Report\r\n\r\n##### COMPONENT NAME\r\nec2_lc_find\r\n\r\n##### ANSIBLE VERSION\r\n```\r\nansible 2.2.0.0\r\n  config file = /home/centos/ansiblebase/ansible.cfg\r\n  configured module search path = Default w/o overrides\r\n```\r\n\r\n##### CONFIGURATION\r\nNo significant changes\r\n\r\n##### OS / ENVIRONMENT\r\nStarted with Ansible Tower 3.0.3 on CentOS 7 x86_64\r\nDid a yum update on ansible to 2.2.\r\nDid pip install boto3.\r\n\r\n##### SUMMARY\r\nRunning ec2_lc_find fails with a missing key for AssociatePublicIpAddress\r\n\r\n##### STEPS TO REPRODUCE\r\n```\r\n- ec2_lc_find:\r\n    region: \"{{ region }}\"\r\n    name_regex: lc_name-*\"\r\n    sort_order: ascending\r\n    limit: 3\r\n  register: old_lc_result\r\n```\r\n\r\n<!--- You can also paste gist.github.com links for larger files -->\r\n\r\n##### EXPECTED RESULTS\r\nCorrectly returns load configurations matching regex.\r\n\r\n##### ACTUAL RESULTS\r\n```\r\nAn exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'AssociatePublicIpAddress'\r\nfatal: [localhost]: FAILED! => {\"changed\": false, \"failed\": true, \"module_stderr\": \"Traceback (most recent call last):\\n  File \\\"/tmp/ansible_dJ3ho0/ansible_module_ec2_lc_find.py\\\", line 225, in <module>\\n    main()\\n  File \\\"/tmp/ansible_dJ3ho0/ansible_module_ec2_lc_find.py\\\", line 217, in main\\n    find_launch_configs(client, module)\\n  File \\\"/tmp/ansible_dJ3ho0/ansible_module_ec2_lc_find.py\\\", line 187, in find_launch_configs\\n    'associate_public_address': lc['AssociatePublicIpAddress'],\\nKeyError: 'AssociatePublicIpAddress'\\n\", \"module_stdout\": \"\", \"msg\": \"MODULE FAILURE\"}\r\n```\r\n\n", "before_files": [{"content": "#!/usr/bin/python\n# encoding: utf-8\n\n# (c) 2015, Jose Armesto <jose@armesto.net>\n#\n# This file is part of Ansible\n#\n# This module is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# This software is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this software.  If not, see <http://www.gnu.org/licenses/>.\n\nDOCUMENTATION = \"\"\"\n---\nmodule: ec2_lc_find\nshort_description: Find AWS Autoscaling Launch Configurations\ndescription:\n  - Returns list of matching Launch Configurations for a given name, along with other useful information\n  - Results can be sorted and sliced\n  - It depends on boto\n  - Based on the work by Tom Bamford (https://github.com/tombamford)\n\nversion_added: \"2.2\"\nauthor: \"Jose Armesto (@fiunchinho)\"\noptions:\n  region:\n    description:\n      - The AWS region to use.\n    required: true\n    aliases: ['aws_region', 'ec2_region']\n  name_regex:\n    description:\n      - A Launch Configuration to match\n      - It'll be compiled as regex\n    required: True\n  sort_order:\n    description:\n      - Order in which to sort results.\n    choices: ['ascending', 'descending']\n    default: 'ascending'\n    required: false\n  limit:\n    description:\n      - How many results to show.\n      - Corresponds to Python slice notation like list[:limit].\n    default: null\n    required: false\nrequirements:\n  - \"python >= 2.6\"\n  - boto3\n\"\"\"\n\nEXAMPLES = '''\n# Note: These examples do not set authentication details, see the AWS Guide for details.\n\n# Search for the Launch Configurations that start with \"app\"\n- ec2_lc_find:\n    name_regex: app.*\n    sort_order: descending\n    limit: 2\n'''\n\nRETURN = '''\nimage_id:\n    description: AMI id\n    returned: when Launch Configuration was found\n    type: string\n    sample: \"ami-0d75df7e\"\nuser_data:\n    description: User data used to start instance\n    returned: when Launch Configuration was found\n    type: string\n    user_data: \"ZXhwb3J0IENMT1VE\"\nname:\n    description: Name of the AMI\n    returned: when Launch Configuration was found\n    type: string\n    sample: \"myapp-v123\"\narn:\n    description: Name of the AMI\n    returned: when Launch Configuration was found\n    type: string\n    sample: \"arn:aws:autoscaling:eu-west-1:12345:launchConfiguration:d82f050e-e315:launchConfigurationName/yourproject\"\ninstance_type:\n    description: Type of ec2 instance\n    returned: when Launch Configuration was found\n    type: string\n    sample: \"t2.small\"\ncreated_time:\n    description: When it was created\n    returned: when Launch Configuration was found\n    type: string\n    sample: \"2016-06-29T14:59:22.222000+00:00\"\nebs_optimized:\n    description: Launch Configuration EBS optimized property\n    returned: when Launch Configuration was found\n    type: boolean\n    sample: False\ninstance_monitoring:\n    description: Launch Configuration instance monitoring property\n    returned: when Launch Configuration was found\n    type: string\n    sample: {\"Enabled\": false}\nclassic_link_vpc_security_groups:\n    description: Launch Configuration classic link vpc security groups property\n    returned: when Launch Configuration was found\n    type: list\n    sample: []\nblock_device_mappings:\n    description: Launch Configuration block device mappings property\n    returned: when Launch Configuration was found\n    type: list\n    sample: []\nkeyname:\n    description: Launch Configuration ssh key\n    returned: when Launch Configuration was found\n    type: string\n    sample: mykey\nsecurity_groups:\n    description: Launch Configuration security groups\n    returned: when Launch Configuration was found\n    type: list\n    sample: []\nkernel_id:\n    description: Launch Configuration kernel to use\n    returned: when Launch Configuration was found\n    type: string\n    sample: ''\nram_disk_id:\n    description: Launch Configuration ram disk property\n    returned: when Launch Configuration was found\n    type: string\n    sample: ''\nassociate_public_address:\n    description: Assign public address or not\n    returned: when Launch Configuration was found\n    type: boolean\n    sample: True\n...\n'''\n\n\ndef find_launch_configs(client, module):\n    name_regex = module.params.get('name_regex')\n    sort_order = module.params.get('sort_order')\n    limit = module.params.get('limit')\n\n    paginator = client.get_paginator('describe_launch_configurations')\n\n    response_iterator = paginator.paginate(\n        PaginationConfig={\n            'MaxItems': 1000,\n            'PageSize': 100\n        }\n    )\n\n    results = []\n\n    for response in response_iterator:\n        response['LaunchConfigurations'] = filter(lambda lc: re.compile(name_regex).match(lc['LaunchConfigurationName']),\n                                                  response['LaunchConfigurations'])\n\n        for lc in response['LaunchConfigurations']:\n            data = {\n                'name': lc['LaunchConfigurationName'],\n                'arn': lc['LaunchConfigurationARN'],\n                'created_time': lc['CreatedTime'],\n                'user_data': lc['UserData'],\n                'instance_type': lc['InstanceType'],\n                'image_id': lc['ImageId'],\n                'ebs_optimized': lc['EbsOptimized'],\n                'instance_monitoring': lc['InstanceMonitoring'],\n                'classic_link_vpc_security_groups': lc['ClassicLinkVPCSecurityGroups'],\n                'block_device_mappings': lc['BlockDeviceMappings'],\n                'keyname': lc['KeyName'],\n                'security_groups': lc['SecurityGroups'],\n                'kernel_id': lc['KernelId'],\n                'ram_disk_id': lc['RamdiskId'],\n                'associate_public_address': lc['AssociatePublicIpAddress'],\n            }\n\n            results.append(data)\n\n    results.sort(key=lambda e: e['name'], reverse=(sort_order == 'descending'))\n\n    if limit:\n        results = results[:int(limit)]\n\n    module.exit_json(changed=False, results=results)\n\n\ndef main():\n    argument_spec = ec2_argument_spec()\n    argument_spec.update(dict(\n        region=dict(required=True, aliases=['aws_region', 'ec2_region']),\n        name_regex=dict(required=True),\n        sort_order=dict(required=False, default='ascending', choices=['ascending', 'descending']),\n        limit=dict(required=False, type='int'),\n    )\n    )\n\n    module = AnsibleModule(\n        argument_spec=argument_spec,\n    )\n\n    region, ec2_url, aws_connect_params = get_aws_connection_info(module, True)\n\n    client = boto3_conn(module=module, conn_type='client', resource='autoscaling', region=region, **aws_connect_params)\n    find_launch_configs(client, module)\n\n\n# import module snippets\nfrom ansible.module_utils.basic import *\nfrom ansible.module_utils.ec2 import *\n\nif __name__ == '__main__':\n    main()\n", "path": "cloud/amazon/ec2_lc_find.py"}], "after_files": [{"content": "#!/usr/bin/python\n# encoding: utf-8\n\n# (c) 2015, Jose Armesto <jose@armesto.net>\n#\n# This file is part of Ansible\n#\n# This module is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# This software is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this software.  If not, see <http://www.gnu.org/licenses/>.\n\nDOCUMENTATION = \"\"\"\n---\nmodule: ec2_lc_find\nshort_description: Find AWS Autoscaling Launch Configurations\ndescription:\n  - Returns list of matching Launch Configurations for a given name, along with other useful information\n  - Results can be sorted and sliced\n  - It depends on boto\n  - Based on the work by Tom Bamford (https://github.com/tombamford)\n\nversion_added: \"2.2\"\nauthor: \"Jose Armesto (@fiunchinho)\"\noptions:\n  region:\n    description:\n      - The AWS region to use.\n    required: true\n    aliases: ['aws_region', 'ec2_region']\n  name_regex:\n    description:\n      - A Launch Configuration to match\n      - It'll be compiled as regex\n    required: True\n  sort_order:\n    description:\n      - Order in which to sort results.\n    choices: ['ascending', 'descending']\n    default: 'ascending'\n    required: false\n  limit:\n    description:\n      - How many results to show.\n      - Corresponds to Python slice notation like list[:limit].\n    default: null\n    required: false\nrequirements:\n  - \"python >= 2.6\"\n  - boto3\n\"\"\"\n\nEXAMPLES = '''\n# Note: These examples do not set authentication details, see the AWS Guide for details.\n\n# Search for the Launch Configurations that start with \"app\"\n- ec2_lc_find:\n    name_regex: app.*\n    sort_order: descending\n    limit: 2\n'''\n\nRETURN = '''\nimage_id:\n    description: AMI id\n    returned: when Launch Configuration was found\n    type: string\n    sample: \"ami-0d75df7e\"\nuser_data:\n    description: User data used to start instance\n    returned: when Launch Configuration was found\n    type: string\n    user_data: \"ZXhwb3J0IENMT1VE\"\nname:\n    description: Name of the AMI\n    returned: when Launch Configuration was found\n    type: string\n    sample: \"myapp-v123\"\narn:\n    description: Name of the AMI\n    returned: when Launch Configuration was found\n    type: string\n    sample: \"arn:aws:autoscaling:eu-west-1:12345:launchConfiguration:d82f050e-e315:launchConfigurationName/yourproject\"\ninstance_type:\n    description: Type of ec2 instance\n    returned: when Launch Configuration was found\n    type: string\n    sample: \"t2.small\"\ncreated_time:\n    description: When it was created\n    returned: when Launch Configuration was found\n    type: string\n    sample: \"2016-06-29T14:59:22.222000+00:00\"\nebs_optimized:\n    description: Launch Configuration EBS optimized property\n    returned: when Launch Configuration was found\n    type: boolean\n    sample: False\ninstance_monitoring:\n    description: Launch Configuration instance monitoring property\n    returned: when Launch Configuration was found\n    type: string\n    sample: {\"Enabled\": false}\nclassic_link_vpc_security_groups:\n    description: Launch Configuration classic link vpc security groups property\n    returned: when Launch Configuration was found\n    type: list\n    sample: []\nblock_device_mappings:\n    description: Launch Configuration block device mappings property\n    returned: when Launch Configuration was found\n    type: list\n    sample: []\nkeyname:\n    description: Launch Configuration ssh key\n    returned: when Launch Configuration was found\n    type: string\n    sample: mykey\nsecurity_groups:\n    description: Launch Configuration security groups\n    returned: when Launch Configuration was found\n    type: list\n    sample: []\nkernel_id:\n    description: Launch Configuration kernel to use\n    returned: when Launch Configuration was found\n    type: string\n    sample: ''\nram_disk_id:\n    description: Launch Configuration ram disk property\n    returned: when Launch Configuration was found\n    type: string\n    sample: ''\nassociate_public_address:\n    description: Assign public address or not\n    returned: when Launch Configuration was found\n    type: boolean\n    sample: True\n...\n'''\n\n\ndef find_launch_configs(client, module):\n    name_regex = module.params.get('name_regex')\n    sort_order = module.params.get('sort_order')\n    limit = module.params.get('limit')\n\n    paginator = client.get_paginator('describe_launch_configurations')\n\n    response_iterator = paginator.paginate(\n        PaginationConfig={\n            'MaxItems': 1000,\n            'PageSize': 100\n        }\n    )\n\n    results = []\n\n    for response in response_iterator:\n        response['LaunchConfigurations'] = filter(lambda lc: re.compile(name_regex).match(lc['LaunchConfigurationName']),\n                                                  response['LaunchConfigurations'])\n\n        for lc in response['LaunchConfigurations']:\n            data = {\n                'name': lc['LaunchConfigurationName'],\n                'arn': lc['LaunchConfigurationARN'],\n                'created_time': lc['CreatedTime'],\n                'user_data': lc['UserData'],\n                'instance_type': lc['InstanceType'],\n                'image_id': lc['ImageId'],\n                'ebs_optimized': lc['EbsOptimized'],\n                'instance_monitoring': lc['InstanceMonitoring'],\n                'classic_link_vpc_security_groups': lc['ClassicLinkVPCSecurityGroups'],\n                'block_device_mappings': lc['BlockDeviceMappings'],\n                'keyname': lc['KeyName'],\n                'security_groups': lc['SecurityGroups'],\n                'kernel_id': lc['KernelId'],\n                'ram_disk_id': lc['RamdiskId'],\n                'associate_public_address': lc.get('AssociatePublicIpAddress', False),\n            }\n\n            results.append(data)\n\n    results.sort(key=lambda e: e['name'], reverse=(sort_order == 'descending'))\n\n    if limit:\n        results = results[:int(limit)]\n\n    module.exit_json(changed=False, results=results)\n\n\ndef main():\n    argument_spec = ec2_argument_spec()\n    argument_spec.update(dict(\n        region=dict(required=True, aliases=['aws_region', 'ec2_region']),\n        name_regex=dict(required=True),\n        sort_order=dict(required=False, default='ascending', choices=['ascending', 'descending']),\n        limit=dict(required=False, type='int'),\n    )\n    )\n\n    module = AnsibleModule(\n        argument_spec=argument_spec,\n    )\n\n    region, ec2_url, aws_connect_params = get_aws_connection_info(module, True)\n\n    client = boto3_conn(module=module, conn_type='client', resource='autoscaling', region=region, **aws_connect_params)\n    find_launch_configs(client, module)\n\n\n# import module snippets\nfrom ansible.module_utils.basic import *\nfrom ansible.module_utils.ec2 import *\n\nif __name__ == '__main__':\n    main()\n", "path": "cloud/amazon/ec2_lc_find.py"}]}