Use filters attribute rather than eni id so facts can be filtered on much more. Matches the new ec2_vpc_route_table_facts and ec2_vpc_subnet_facts modules
This commit is contained in:
parent
15480e3d04
commit
62cd2d9c18
1 changed files with 11 additions and 18 deletions
|
@ -22,11 +22,12 @@ description:
|
|||
version_added: "2.0"
|
||||
author: "Rob White (@wimnat)"
|
||||
options:
|
||||
eni_id:
|
||||
filters:
|
||||
description:
|
||||
- The ID of the ENI. Pass this option to gather facts about a particular ENI, otherwise, all ENIs are returned.
|
||||
- A dict of filters to apply. Each dict item consists of a filter key and a filter value. See U(http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeNetworkInterfaces.html) for possible filters.
|
||||
required: false
|
||||
default: null
|
||||
|
||||
extends_documentation_fragment:
|
||||
- aws
|
||||
- ec2
|
||||
|
@ -40,12 +41,11 @@ EXAMPLES = '''
|
|||
|
||||
# Gather facts about a particular ENI
|
||||
- ec2_eni_facts:
|
||||
eni_id: eni-xxxxxxx
|
||||
filters:
|
||||
network-interface-id: eni-xxxxxxx
|
||||
|
||||
'''
|
||||
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
try:
|
||||
import boto.ec2
|
||||
from boto.exception import BotoServerError
|
||||
|
@ -53,14 +53,6 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
|
||||
def get_error_message(xml_string):
|
||||
|
||||
root = ET.fromstring(xml_string)
|
||||
for message in root.findall('.//Message'):
|
||||
return message.text
|
||||
|
||||
|
||||
def get_eni_info(interface):
|
||||
|
||||
interface_info = {'id': interface.id,
|
||||
|
@ -89,13 +81,13 @@ def get_eni_info(interface):
|
|||
|
||||
def list_eni(connection, module):
|
||||
|
||||
eni_id = module.params.get("eni_id")
|
||||
filters = module.params.get("filters")
|
||||
interface_dict_array = []
|
||||
|
||||
try:
|
||||
all_eni = connection.get_all_network_interfaces(eni_id)
|
||||
all_eni = connection.get_all_network_interfaces(filters=filters)
|
||||
except BotoServerError as e:
|
||||
module.fail_json(msg=get_error_message(e.args[2]))
|
||||
module.fail_json(msg=e.message)
|
||||
|
||||
for interface in all_eni:
|
||||
interface_dict_array.append(get_eni_info(interface))
|
||||
|
@ -107,7 +99,7 @@ def main():
|
|||
argument_spec = ec2_argument_spec()
|
||||
argument_spec.update(
|
||||
dict(
|
||||
eni_id = dict(default=None)
|
||||
filters = dict(default=None, type='dict')
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -131,4 +123,5 @@ def main():
|
|||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue