We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
ec2_elb_facts should support check mode
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ec2_elb_facts

##### ANSIBLE VERSION

```
ansible 2.2.0.0
  config file = 
  configured module search path = Default w/o overrides
```

##### CONFIGURATION
*N/A*

##### OS / ENVIRONMENT
*N/A*

##### SUMMARY
Since the `ec2_elb_facts` is strictly a read-only operation, it should support running with `--check`

##### STEPS TO REPRODUCE

```sh
ansible-playbook \
    -i hosts \
    -l my-elb-host \
    ec2_elb_facts_check.yml \
    -vv \
    --check
```

```yaml
- hosts: all
  connection: local
  gather_facts: no

  tasks:
    - name: Collect ELB facts
      ec2_elb_facts:
        names: "my-elb"
        region: "us-east-1"
      register: elbfacts
      tags: always
```

##### EXPECTED RESULTS
It would be expected that `ec2_elb_facts` would still fetch the instance information. This being omitted, prevents the ability to enumerate ELB instance hosts, dynamically add them to the inventory, and then conduct `--check` mode against what would *actually* be getting done.

##### ACTUAL RESULTS

```
TASK [Collect ELB facts] ***********************************************
task path: /Projects/ec2_elb_facts_check.yml:6
skipping: [my-elb-host] => {
    "changed": false, 
    "skipped": true
}

MSG:

remote module (ec2_elb_facts) does not support check mode
```

--- 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_elb_facts.py`
Content:
```
1 #!/usr/bin/python
2 #
3 # This is a free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This Ansible library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this library.  If not, see <http://www.gnu.org/licenses/>.
15 
16 DOCUMENTATION = '''
17 ---
18 module: ec2_elb_facts
19 short_description: Gather facts about EC2 Elastic Load Balancers in AWS
20 description:
21     - Gather facts about EC2 Elastic Load Balancers in AWS
22 version_added: "2.0"
23 author:
24   - "Michael Schultz (github.com/mjschultz)"
25   - "Fernando Jose Pando (@nand0p)"
26 options:
27   names:
28     description:
29       - List of ELB names to gather facts about. Pass this option to gather facts about a set of ELBs, otherwise, all ELBs are returned.
30     required: false
31     default: null
32     aliases: ['elb_ids', 'ec2_elbs']
33 extends_documentation_fragment:
34     - aws
35     - ec2
36 '''
37 
38 EXAMPLES = '''
39 # Note: These examples do not set authentication details, see the AWS Guide for details.
40 # Output format tries to match ec2_elb_lb module input parameters
41 
42 # Gather facts about all ELBs
43 - action:
44     module: ec2_elb_facts
45   register: elb_facts
46 
47 - action:
48     module: debug
49     msg: "{{ item.dns_name }}"
50   with_items: "{{ elb_facts.elbs }}"
51 
52 # Gather facts about a particular ELB
53 - action:
54     module: ec2_elb_facts
55     names: frontend-prod-elb
56   register: elb_facts
57 
58 - action:
59     module: debug
60     msg: "{{ elb_facts.elbs.0.dns_name }}"
61 
62 # Gather facts about a set of ELBs
63 - action:
64     module: ec2_elb_facts
65     names:
66     - frontend-prod-elb
67     - backend-prod-elb
68   register: elb_facts
69 
70 - action:
71     module: debug
72     msg: "{{ item.dns_name }}"
73   with_items: "{{ elb_facts.elbs }}"
74 
75 '''
76 
77 try:
78     import boto.ec2.elb
79     from boto.ec2.tag import Tag
80     from boto.exception import BotoServerError
81     HAS_BOTO = True
82 except ImportError:
83     HAS_BOTO = False
84 
85 class ElbInformation(object):
86     """ Handles ELB information """
87 
88     def __init__(self,
89                  module,
90                  names,
91                  region,
92                  **aws_connect_params):
93 
94         self.module = module
95         self.names = names
96         self.region = region
97         self.aws_connect_params = aws_connect_params
98         self.connection = self._get_elb_connection()
99 
100     def _get_tags(self, elbname):
101         params = {'LoadBalancerNames.member.1': elbname}
102         try:
103             elb_tags = self.connection.get_list('DescribeTags', params, [('member', Tag)])
104             return dict((tag.Key, tag.Value) for tag in elb_tags if hasattr(tag, 'Key'))
105         except:
106             return {}
107 
108     def _get_elb_connection(self):
109         try:
110             return connect_to_aws(boto.ec2.elb, self.region, **self.aws_connect_params)
111         except BotoServerError as err:
112             self.module.fail_json(msg=err.message)
113 
114     def _get_elb_listeners(self, listeners):
115         listener_list = []
116 
117         for listener in listeners:
118             listener_dict = {
119                 'load_balancer_port': listener[0],
120                 'instance_port': listener[1],
121                 'protocol': listener[2],
122             }
123 
124             try:
125                 ssl_certificate_id = listener[4]
126             except IndexError:
127                 pass
128             else:
129                 if ssl_certificate_id:
130                     listener_dict['ssl_certificate_id'] = ssl_certificate_id
131 
132             listener_list.append(listener_dict)
133 
134         return listener_list
135 
136     def _get_health_check(self, health_check):
137         protocol, port_path = health_check.target.split(':')
138         try:
139             port, path = port_path.split('/', 1)
140             path = '/{}'.format(path)
141         except ValueError:
142             port = port_path
143             path = None
144 
145         health_check_dict = {
146             'ping_protocol': protocol.lower(),
147             'ping_port': int(port),
148             'response_timeout': health_check.timeout,
149             'interval': health_check.interval,
150             'unhealthy_threshold': health_check.unhealthy_threshold,
151             'healthy_threshold': health_check.healthy_threshold,
152         }
153 
154         if path:
155             health_check_dict['ping_path'] = path
156         return health_check_dict
157 
158     def _get_elb_info(self, elb):
159         elb_info = {
160             'name': elb.name,
161             'zones': elb.availability_zones,
162             'dns_name': elb.dns_name,
163             'canonical_hosted_zone_name': elb.canonical_hosted_zone_name,
164             'canonical_hosted_zone_name_id': elb.canonical_hosted_zone_name_id,
165             'hosted_zone_name': elb.canonical_hosted_zone_name,
166             'hosted_zone_id': elb.canonical_hosted_zone_name_id,
167             'instances': [instance.id for instance in elb.instances],
168             'listeners': self._get_elb_listeners(elb.listeners),
169             'scheme': elb.scheme,
170             'security_groups': elb.security_groups,
171             'health_check': self._get_health_check(elb.health_check),
172             'subnets': elb.subnets,
173             'instances_inservice': [],
174             'instances_inservice_count': 0,
175             'instances_outofservice': [],
176             'instances_outofservice_count': 0,
177             'instances_inservice_percent': 0.0,
178             'tags': self._get_tags(elb.name)
179         }
180 
181         if elb.vpc_id:
182             elb_info['vpc_id'] = elb.vpc_id
183 
184         if elb.instances:
185             try:
186                 instance_health = self.connection.describe_instance_health(elb.name)
187             except BotoServerError as err:
188                 self.module.fail_json(msg=err.message)
189             elb_info['instances_inservice'] = [inst.instance_id for inst in instance_health if inst.state == 'InService']
190             elb_info['instances_inservice_count'] = len(elb_info['instances_inservice'])
191             elb_info['instances_outofservice'] = [inst.instance_id for inst in instance_health if inst.state == 'OutOfService']
192             elb_info['instances_outofservice_count'] = len(elb_info['instances_outofservice'])
193             elb_info['instances_inservice_percent'] = float(elb_info['instances_inservice_count'])/(
194                         float(elb_info['instances_inservice_count']) +
195                         float(elb_info['instances_outofservice_count']))*100
196         return elb_info
197 
198 
199     def list_elbs(self):
200         elb_array = []
201 
202         try:
203             all_elbs = self.connection.get_all_load_balancers()
204         except BotoServerError as err:
205             self.module.fail_json(msg = "%s: %s" % (err.error_code, err.error_message))
206 
207         if all_elbs:
208             if self.names:
209                 for existing_lb in all_elbs:
210                     if existing_lb.name in self.names:
211                         elb_array.append(existing_lb)
212             else:
213                 elb_array = all_elbs
214                     
215         return list(map(self._get_elb_info, elb_array))
216 
217 def main():
218     argument_spec = ec2_argument_spec()
219     argument_spec.update(dict(
220             names={'default': [], 'type': 'list'}
221         )
222     )
223     module = AnsibleModule(argument_spec=argument_spec)
224 
225     if not HAS_BOTO:
226         module.fail_json(msg='boto required for this module')
227 
228     region, ec2_url, aws_connect_params = get_aws_connection_info(module)
229 
230     if not region:
231         module.fail_json(msg="region must be specified")
232 
233     names = module.params['names']
234     elb_information = ElbInformation(module,
235                               names,
236                               region,
237                               **aws_connect_params)
238 
239     ec2_facts_result = dict(changed=False,
240                             elbs=elb_information.list_elbs())
241 
242     module.exit_json(**ec2_facts_result)
243 
244 from ansible.module_utils.basic import *
245 from ansible.module_utils.ec2 import *
246 
247 if __name__ == '__main__':
248     main()
249
```
--- 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_elb_facts.py b/cloud/amazon/ec2_elb_facts.py
--- a/cloud/amazon/ec2_elb_facts.py
+++ b/cloud/amazon/ec2_elb_facts.py
@@ -220,7 +220,8 @@
             names={'default': [], 'type': 'list'}
         )
     )
-    module = AnsibleModule(argument_spec=argument_spec)
+    module = AnsibleModule(argument_spec=argument_spec,
+                           supports_check_mode=True)
 
     if not HAS_BOTO:
         module.fail_json(msg='boto required for this module')

{"golden_diff": "diff --git a/cloud/amazon/ec2_elb_facts.py b/cloud/amazon/ec2_elb_facts.py\n--- a/cloud/amazon/ec2_elb_facts.py\n+++ b/cloud/amazon/ec2_elb_facts.py\n@@ -220,7 +220,8 @@\n             names={'default': [], 'type': 'list'}\n         )\n     )\n-    module = AnsibleModule(argument_spec=argument_spec)\n+    module = AnsibleModule(argument_spec=argument_spec,\n+                           supports_check_mode=True)\n \n     if not HAS_BOTO:\n         module.fail_json(msg='boto required for this module')\n", "issue": "ec2_elb_facts should support check mode\n##### ISSUE TYPE\r\n - Bug Report\r\n\r\n##### COMPONENT NAME\r\nec2_elb_facts\r\n\r\n##### ANSIBLE VERSION\r\n\r\n```\r\nansible 2.2.0.0\r\n  config file = \r\n  configured module search path = Default w/o overrides\r\n```\r\n\r\n##### CONFIGURATION\r\n*N/A*\r\n\r\n##### OS / ENVIRONMENT\r\n*N/A*\r\n\r\n##### SUMMARY\r\nSince the `ec2_elb_facts` is strictly a read-only operation, it should support running with `--check`\r\n\r\n##### STEPS TO REPRODUCE\r\n\r\n```sh\r\nansible-playbook \\\r\n    -i hosts \\\r\n    -l my-elb-host \\\r\n    ec2_elb_facts_check.yml \\\r\n    -vv \\\r\n    --check\r\n```\r\n\r\n```yaml\r\n- hosts: all\r\n  connection: local\r\n  gather_facts: no\r\n\r\n  tasks:\r\n    - name: Collect ELB facts\r\n      ec2_elb_facts:\r\n        names: \"my-elb\"\r\n        region: \"us-east-1\"\r\n      register: elbfacts\r\n      tags: always\r\n```\r\n\r\n##### EXPECTED RESULTS\r\nIt would be expected that `ec2_elb_facts` would still fetch the instance information. This being omitted, prevents the ability to enumerate ELB instance hosts, dynamically add them to the inventory, and then conduct `--check` mode against what would *actually* be getting done.\r\n\r\n##### ACTUAL RESULTS\r\n\r\n```\r\nTASK [Collect ELB facts] ***********************************************\r\ntask path: /Projects/ec2_elb_facts_check.yml:6\r\nskipping: [my-elb-host] => {\r\n    \"changed\": false, \r\n    \"skipped\": true\r\n}\r\n\r\nMSG:\r\n\r\nremote module (ec2_elb_facts) does not support check mode\r\n```\n", "before_files": [{"content": "#!/usr/bin/python\n#\n# This is a 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 Ansible library 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 library.  If not, see <http://www.gnu.org/licenses/>.\n\nDOCUMENTATION = '''\n---\nmodule: ec2_elb_facts\nshort_description: Gather facts about EC2 Elastic Load Balancers in AWS\ndescription:\n    - Gather facts about EC2 Elastic Load Balancers in AWS\nversion_added: \"2.0\"\nauthor:\n  - \"Michael Schultz (github.com/mjschultz)\"\n  - \"Fernando Jose Pando (@nand0p)\"\noptions:\n  names:\n    description:\n      - List of ELB names to gather facts about. Pass this option to gather facts about a set of ELBs, otherwise, all ELBs are returned.\n    required: false\n    default: null\n    aliases: ['elb_ids', 'ec2_elbs']\nextends_documentation_fragment:\n    - aws\n    - ec2\n'''\n\nEXAMPLES = '''\n# Note: These examples do not set authentication details, see the AWS Guide for details.\n# Output format tries to match ec2_elb_lb module input parameters\n\n# Gather facts about all ELBs\n- action:\n    module: ec2_elb_facts\n  register: elb_facts\n\n- action:\n    module: debug\n    msg: \"{{ item.dns_name }}\"\n  with_items: \"{{ elb_facts.elbs }}\"\n\n# Gather facts about a particular ELB\n- action:\n    module: ec2_elb_facts\n    names: frontend-prod-elb\n  register: elb_facts\n\n- action:\n    module: debug\n    msg: \"{{ elb_facts.elbs.0.dns_name }}\"\n\n# Gather facts about a set of ELBs\n- action:\n    module: ec2_elb_facts\n    names:\n    - frontend-prod-elb\n    - backend-prod-elb\n  register: elb_facts\n\n- action:\n    module: debug\n    msg: \"{{ item.dns_name }}\"\n  with_items: \"{{ elb_facts.elbs }}\"\n\n'''\n\ntry:\n    import boto.ec2.elb\n    from boto.ec2.tag import Tag\n    from boto.exception import BotoServerError\n    HAS_BOTO = True\nexcept ImportError:\n    HAS_BOTO = False\n\nclass ElbInformation(object):\n    \"\"\" Handles ELB information \"\"\"\n\n    def __init__(self,\n                 module,\n                 names,\n                 region,\n                 **aws_connect_params):\n\n        self.module = module\n        self.names = names\n        self.region = region\n        self.aws_connect_params = aws_connect_params\n        self.connection = self._get_elb_connection()\n\n    def _get_tags(self, elbname):\n        params = {'LoadBalancerNames.member.1': elbname}\n        try:\n            elb_tags = self.connection.get_list('DescribeTags', params, [('member', Tag)])\n            return dict((tag.Key, tag.Value) for tag in elb_tags if hasattr(tag, 'Key'))\n        except:\n            return {}\n\n    def _get_elb_connection(self):\n        try:\n            return connect_to_aws(boto.ec2.elb, self.region, **self.aws_connect_params)\n        except BotoServerError as err:\n            self.module.fail_json(msg=err.message)\n\n    def _get_elb_listeners(self, listeners):\n        listener_list = []\n\n        for listener in listeners:\n            listener_dict = {\n                'load_balancer_port': listener[0],\n                'instance_port': listener[1],\n                'protocol': listener[2],\n            }\n\n            try:\n                ssl_certificate_id = listener[4]\n            except IndexError:\n                pass\n            else:\n                if ssl_certificate_id:\n                    listener_dict['ssl_certificate_id'] = ssl_certificate_id\n\n            listener_list.append(listener_dict)\n\n        return listener_list\n\n    def _get_health_check(self, health_check):\n        protocol, port_path = health_check.target.split(':')\n        try:\n            port, path = port_path.split('/', 1)\n            path = '/{}'.format(path)\n        except ValueError:\n            port = port_path\n            path = None\n\n        health_check_dict = {\n            'ping_protocol': protocol.lower(),\n            'ping_port': int(port),\n            'response_timeout': health_check.timeout,\n            'interval': health_check.interval,\n            'unhealthy_threshold': health_check.unhealthy_threshold,\n            'healthy_threshold': health_check.healthy_threshold,\n        }\n\n        if path:\n            health_check_dict['ping_path'] = path\n        return health_check_dict\n\n    def _get_elb_info(self, elb):\n        elb_info = {\n            'name': elb.name,\n            'zones': elb.availability_zones,\n            'dns_name': elb.dns_name,\n            'canonical_hosted_zone_name': elb.canonical_hosted_zone_name,\n            'canonical_hosted_zone_name_id': elb.canonical_hosted_zone_name_id,\n            'hosted_zone_name': elb.canonical_hosted_zone_name,\n            'hosted_zone_id': elb.canonical_hosted_zone_name_id,\n            'instances': [instance.id for instance in elb.instances],\n            'listeners': self._get_elb_listeners(elb.listeners),\n            'scheme': elb.scheme,\n            'security_groups': elb.security_groups,\n            'health_check': self._get_health_check(elb.health_check),\n            'subnets': elb.subnets,\n            'instances_inservice': [],\n            'instances_inservice_count': 0,\n            'instances_outofservice': [],\n            'instances_outofservice_count': 0,\n            'instances_inservice_percent': 0.0,\n            'tags': self._get_tags(elb.name)\n        }\n\n        if elb.vpc_id:\n            elb_info['vpc_id'] = elb.vpc_id\n\n        if elb.instances:\n            try:\n                instance_health = self.connection.describe_instance_health(elb.name)\n            except BotoServerError as err:\n                self.module.fail_json(msg=err.message)\n            elb_info['instances_inservice'] = [inst.instance_id for inst in instance_health if inst.state == 'InService']\n            elb_info['instances_inservice_count'] = len(elb_info['instances_inservice'])\n            elb_info['instances_outofservice'] = [inst.instance_id for inst in instance_health if inst.state == 'OutOfService']\n            elb_info['instances_outofservice_count'] = len(elb_info['instances_outofservice'])\n            elb_info['instances_inservice_percent'] = float(elb_info['instances_inservice_count'])/(\n                        float(elb_info['instances_inservice_count']) +\n                        float(elb_info['instances_outofservice_count']))*100\n        return elb_info\n\n\n    def list_elbs(self):\n        elb_array = []\n\n        try:\n            all_elbs = self.connection.get_all_load_balancers()\n        except BotoServerError as err:\n            self.module.fail_json(msg = \"%s: %s\" % (err.error_code, err.error_message))\n\n        if all_elbs:\n            if self.names:\n                for existing_lb in all_elbs:\n                    if existing_lb.name in self.names:\n                        elb_array.append(existing_lb)\n            else:\n                elb_array = all_elbs\n                    \n        return list(map(self._get_elb_info, elb_array))\n\ndef main():\n    argument_spec = ec2_argument_spec()\n    argument_spec.update(dict(\n            names={'default': [], 'type': 'list'}\n        )\n    )\n    module = AnsibleModule(argument_spec=argument_spec)\n\n    if not HAS_BOTO:\n        module.fail_json(msg='boto required for this module')\n\n    region, ec2_url, aws_connect_params = get_aws_connection_info(module)\n\n    if not region:\n        module.fail_json(msg=\"region must be specified\")\n\n    names = module.params['names']\n    elb_information = ElbInformation(module,\n                              names,\n                              region,\n                              **aws_connect_params)\n\n    ec2_facts_result = dict(changed=False,\n                            elbs=elb_information.list_elbs())\n\n    module.exit_json(**ec2_facts_result)\n\nfrom ansible.module_utils.basic import *\nfrom ansible.module_utils.ec2 import *\n\nif __name__ == '__main__':\n    main()\n", "path": "cloud/amazon/ec2_elb_facts.py"}], "after_files": [{"content": "#!/usr/bin/python\n#\n# This is a 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 Ansible library 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 library.  If not, see <http://www.gnu.org/licenses/>.\n\nDOCUMENTATION = '''\n---\nmodule: ec2_elb_facts\nshort_description: Gather facts about EC2 Elastic Load Balancers in AWS\ndescription:\n    - Gather facts about EC2 Elastic Load Balancers in AWS\nversion_added: \"2.0\"\nauthor:\n  - \"Michael Schultz (github.com/mjschultz)\"\n  - \"Fernando Jose Pando (@nand0p)\"\noptions:\n  names:\n    description:\n      - List of ELB names to gather facts about. Pass this option to gather facts about a set of ELBs, otherwise, all ELBs are returned.\n    required: false\n    default: null\n    aliases: ['elb_ids', 'ec2_elbs']\nextends_documentation_fragment:\n    - aws\n    - ec2\n'''\n\nEXAMPLES = '''\n# Note: These examples do not set authentication details, see the AWS Guide for details.\n# Output format tries to match ec2_elb_lb module input parameters\n\n# Gather facts about all ELBs\n- action:\n    module: ec2_elb_facts\n  register: elb_facts\n\n- action:\n    module: debug\n    msg: \"{{ item.dns_name }}\"\n  with_items: \"{{ elb_facts.elbs }}\"\n\n# Gather facts about a particular ELB\n- action:\n    module: ec2_elb_facts\n    names: frontend-prod-elb\n  register: elb_facts\n\n- action:\n    module: debug\n    msg: \"{{ elb_facts.elbs.0.dns_name }}\"\n\n# Gather facts about a set of ELBs\n- action:\n    module: ec2_elb_facts\n    names:\n    - frontend-prod-elb\n    - backend-prod-elb\n  register: elb_facts\n\n- action:\n    module: debug\n    msg: \"{{ item.dns_name }}\"\n  with_items: \"{{ elb_facts.elbs }}\"\n\n'''\n\ntry:\n    import boto.ec2.elb\n    from boto.ec2.tag import Tag\n    from boto.exception import BotoServerError\n    HAS_BOTO = True\nexcept ImportError:\n    HAS_BOTO = False\n\nclass ElbInformation(object):\n    \"\"\" Handles ELB information \"\"\"\n\n    def __init__(self,\n                 module,\n                 names,\n                 region,\n                 **aws_connect_params):\n\n        self.module = module\n        self.names = names\n        self.region = region\n        self.aws_connect_params = aws_connect_params\n        self.connection = self._get_elb_connection()\n\n    def _get_tags(self, elbname):\n        params = {'LoadBalancerNames.member.1': elbname}\n        try:\n            elb_tags = self.connection.get_list('DescribeTags', params, [('member', Tag)])\n            return dict((tag.Key, tag.Value) for tag in elb_tags if hasattr(tag, 'Key'))\n        except:\n            return {}\n\n    def _get_elb_connection(self):\n        try:\n            return connect_to_aws(boto.ec2.elb, self.region, **self.aws_connect_params)\n        except BotoServerError as err:\n            self.module.fail_json(msg=err.message)\n\n    def _get_elb_listeners(self, listeners):\n        listener_list = []\n\n        for listener in listeners:\n            listener_dict = {\n                'load_balancer_port': listener[0],\n                'instance_port': listener[1],\n                'protocol': listener[2],\n            }\n\n            try:\n                ssl_certificate_id = listener[4]\n            except IndexError:\n                pass\n            else:\n                if ssl_certificate_id:\n                    listener_dict['ssl_certificate_id'] = ssl_certificate_id\n\n            listener_list.append(listener_dict)\n\n        return listener_list\n\n    def _get_health_check(self, health_check):\n        protocol, port_path = health_check.target.split(':')\n        try:\n            port, path = port_path.split('/', 1)\n            path = '/{}'.format(path)\n        except ValueError:\n            port = port_path\n            path = None\n\n        health_check_dict = {\n            'ping_protocol': protocol.lower(),\n            'ping_port': int(port),\n            'response_timeout': health_check.timeout,\n            'interval': health_check.interval,\n            'unhealthy_threshold': health_check.unhealthy_threshold,\n            'healthy_threshold': health_check.healthy_threshold,\n        }\n\n        if path:\n            health_check_dict['ping_path'] = path\n        return health_check_dict\n\n    def _get_elb_info(self, elb):\n        elb_info = {\n            'name': elb.name,\n            'zones': elb.availability_zones,\n            'dns_name': elb.dns_name,\n            'canonical_hosted_zone_name': elb.canonical_hosted_zone_name,\n            'canonical_hosted_zone_name_id': elb.canonical_hosted_zone_name_id,\n            'hosted_zone_name': elb.canonical_hosted_zone_name,\n            'hosted_zone_id': elb.canonical_hosted_zone_name_id,\n            'instances': [instance.id for instance in elb.instances],\n            'listeners': self._get_elb_listeners(elb.listeners),\n            'scheme': elb.scheme,\n            'security_groups': elb.security_groups,\n            'health_check': self._get_health_check(elb.health_check),\n            'subnets': elb.subnets,\n            'instances_inservice': [],\n            'instances_inservice_count': 0,\n            'instances_outofservice': [],\n            'instances_outofservice_count': 0,\n            'instances_inservice_percent': 0.0,\n            'tags': self._get_tags(elb.name)\n        }\n\n        if elb.vpc_id:\n            elb_info['vpc_id'] = elb.vpc_id\n\n        if elb.instances:\n            try:\n                instance_health = self.connection.describe_instance_health(elb.name)\n            except BotoServerError as err:\n                self.module.fail_json(msg=err.message)\n            elb_info['instances_inservice'] = [inst.instance_id for inst in instance_health if inst.state == 'InService']\n            elb_info['instances_inservice_count'] = len(elb_info['instances_inservice'])\n            elb_info['instances_outofservice'] = [inst.instance_id for inst in instance_health if inst.state == 'OutOfService']\n            elb_info['instances_outofservice_count'] = len(elb_info['instances_outofservice'])\n            elb_info['instances_inservice_percent'] = float(elb_info['instances_inservice_count'])/(\n                        float(elb_info['instances_inservice_count']) +\n                        float(elb_info['instances_outofservice_count']))*100\n        return elb_info\n\n\n    def list_elbs(self):\n        elb_array = []\n\n        try:\n            all_elbs = self.connection.get_all_load_balancers()\n        except BotoServerError as err:\n            self.module.fail_json(msg = \"%s: %s\" % (err.error_code, err.error_message))\n\n        if all_elbs:\n            if self.names:\n                for existing_lb in all_elbs:\n                    if existing_lb.name in self.names:\n                        elb_array.append(existing_lb)\n            else:\n                elb_array = all_elbs\n                    \n        return list(map(self._get_elb_info, elb_array))\n\ndef main():\n    argument_spec = ec2_argument_spec()\n    argument_spec.update(dict(\n            names={'default': [], 'type': 'list'}\n        )\n    )\n    module = AnsibleModule(argument_spec=argument_spec,\n                           supports_check_mode=True)\n\n    if not HAS_BOTO:\n        module.fail_json(msg='boto required for this module')\n\n    region, ec2_url, aws_connect_params = get_aws_connection_info(module)\n\n    if not region:\n        module.fail_json(msg=\"region must be specified\")\n\n    names = module.params['names']\n    elb_information = ElbInformation(module,\n                              names,\n                              region,\n                              **aws_connect_params)\n\n    ec2_facts_result = dict(changed=False,\n                            elbs=elb_information.list_elbs())\n\n    module.exit_json(**ec2_facts_result)\n\nfrom ansible.module_utils.basic import *\nfrom ansible.module_utils.ec2 import *\n\nif __name__ == '__main__':\n    main()\n", "path": "cloud/amazon/ec2_elb_facts.py"}]}