3 # Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
5 # This module is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This software is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this software. If not, see <http://www.gnu.org/licenses/>.
26 module: my_os_network_facts
27 short_description: Retrieve facts about one or more OpenStack networks.
29 author: "Davide Agnello (@dagnello)"
31 - Retrieve facts about one or more networks from OpenStack.
38 - Name or ID of the Network
42 - A dictionary of meta data to use for further filtering. Elements of
43 this dictionary may be additional dictionaries.
45 extends_documentation_fragment: openstack
49 # Gather facts about previously created networks
50 - my_os_network_facts:
52 auth_url: https://your_api_url.com:9000/v2.0
55 project_name: someproject
56 - debug: var=openstack_networks
58 # Gather facts about a previously created network by name
59 - my_os_network_facts:
61 auth_url: https://your_api_url.com:9000/v2.0
64 project_name: someproject
66 - debug: var=openstack_networks
68 # Gather facts about a previously created network with filter (note: name and
69 filters parameters are Not mutually exclusive)
70 - my_os_network_facts:
72 auth_url: https://your_api_url.com:9000/v2.0
75 project_name: someproject
77 tenant_id: 55e2ce24b2a245b09f181bf025724cbe
79 - 057d4bdf-6d4d-4728-bb0f-5ac45a6f7400
80 - 443d4dc0-91d4-4998-b21c-357d10433483
81 - debug: var=openstack_networks
86 description: has all the openstack facts about the networks
87 returned: always, but can be null
91 description: Unique UUID.
95 description: Name given to the network.
99 description: Network status.
103 description: Subnet(s) included in this network.
105 type: list of strings
107 description: Tenant id associated with this network.
111 description: Network shared flag.
118 argument_spec = openstack_full_argument_spec(
119 network={'required': False, 'default': None},
120 filters={'required': False, 'default': None}
122 module_kwargs = openstack_module_kwargs()
123 module = AnsibleModule(argument_spec)
126 module.fail_json(msg='shade is required for this module')
128 network = module.params.pop('network')
129 filters = module.params.pop('filters')
132 cloud = shade.openstack_cloud(**module.params)
133 networks = cloud.search_networks(network, filters)
134 module.exit_json(changed=False, ansible_facts={
135 'openstack_networks': networks})
137 except shade.OpenStackCloudException as e:
138 module.fail_json(msg=str(e))
140 # this is magic, see lib/ansible/module_common.py
141 from ansible.module_utils.basic import *
142 from ansible.module_utils.openstack import *
143 if __name__ == '__main__':