ansible  2.9.27
About: Ansible is an IT Configuration Management, Deployment \
About: Ansible (2.x) is an IT Configuration Management, Deployment & Orchestration tool.
ansible download page.
  Fossies Dox: ansible-2.9.27.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

aci_filter.py
Go to the documentation of this file.
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6from __future__ import absolute_import, division, print_function
7__metaclass__ = type
8
9ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'certified'}
12
13DOCUMENTATION = r'''
14---
15module: aci_filter
16short_description: Manages top level filter objects (vz:Filter)
17description:
18- Manages top level filter objects on Cisco ACI fabrics.
19- This modules does not manage filter entries, see M(aci_filter_entry) for this functionality.
20version_added: '2.4'
21options:
22 filter:
23 description:
24 - The name of the filter.
25 type: str
26 required: yes
27 aliases: [ filter_name, name ]
28 description:
29 description:
30 - Description for the filter.
31 type: str
32 aliases: [ descr ]
33 tenant:
34 description:
35 - The name of the tenant.
36 type: str
37 required: yes
38 aliases: [ tenant_name ]
39 state:
40 description:
41 - Use C(present) or C(absent) for adding or removing.
42 - Use C(query) for listing an object or multiple objects.
43 type: str
44 choices: [ absent, present, query ]
45 default: present
46extends_documentation_fragment: aci
47notes:
48- The C(tenant) used must exist before using this module in your playbook.
49 The M(aci_tenant) module can be used for this.
50seealso:
51- module: aci_tenant
52- name: APIC Management Information Model reference
53 description: More information about the internal APIC class B(vz:Filter).
54 link: https://developer.cisco.com/docs/apic-mim-ref/
55author:
56- Dag Wieers (@dagwieers)
57'''
58
59EXAMPLES = r'''
60- name: Add a new filter to a tenant
61 aci_filter:
62 host: apic
63 username: admin
64 password: SomeSecretPassword
65 filter: web_filter
66 description: Filter for web protocols
67 tenant: production
68 state: present
69 delegate_to: localhost
70
71- name: Remove a filter for a tenant
72 aci_filter:
73 host: apic
74 username: admin
75 password: SomeSecretPassword
76 filter: web_filter
77 tenant: production
78 state: absent
79 delegate_to: localhost
80
81- name: Query a filter of a tenant
82 aci_filter:
83 host: apic
84 username: admin
85 password: SomeSecretPassword
86 filter: web_filter
87 tenant: production
88 state: query
89 delegate_to: localhost
90 register: query_result
91
92- name: Query all filters for a tenant
93 aci_filter:
94 host: apic
95 username: admin
96 password: SomeSecretPassword
97 tenant: production
98 state: query
99 delegate_to: localhost
100 register: query_result
101'''
102
103RETURN = r'''
104current:
105 description: The existing configuration from the APIC after the module has finished
106 returned: success
107 type: list
108 sample:
109 [
110 {
111 "fvTenant": {
112 "attributes": {
113 "descr": "Production environment",
114 "dn": "uni/tn-production",
115 "name": "production",
116 "nameAlias": "",
117 "ownerKey": "",
118 "ownerTag": ""
119 }
120 }
121 }
122 ]
123error:
124 description: The error information as returned from the APIC
125 returned: failure
126 type: dict
127 sample:
128 {
129 "code": "122",
130 "text": "unknown managed object class foo"
131 }
132raw:
133 description: The raw output returned by the APIC REST API (xml or json)
134 returned: parse error
135 type: str
136 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
137sent:
138 description: The actual/minimal configuration pushed to the APIC
139 returned: info
140 type: list
141 sample:
142 {
143 "fvTenant": {
144 "attributes": {
145 "descr": "Production environment"
146 }
147 }
148 }
149previous:
150 description: The original configuration from the APIC before the module has started
151 returned: info
152 type: list
153 sample:
154 [
155 {
156 "fvTenant": {
157 "attributes": {
158 "descr": "Production",
159 "dn": "uni/tn-production",
160 "name": "production",
161 "nameAlias": "",
162 "ownerKey": "",
163 "ownerTag": ""
164 }
165 }
166 }
167 ]
168proposed:
169 description: The assembled configuration from the user-provided parameters
170 returned: info
171 type: dict
172 sample:
173 {
174 "fvTenant": {
175 "attributes": {
176 "descr": "Production environment",
177 "name": "production"
178 }
179 }
180 }
181filter_string:
182 description: The filter string used for the request
183 returned: failure or debug
184 type: str
185 sample: ?rsp-prop-include=config-only
186method:
187 description: The HTTP method used for the request to the APIC
188 returned: failure or debug
189 type: str
190 sample: POST
191response:
192 description: The HTTP response from the APIC
193 returned: failure or debug
194 type: str
195 sample: OK (30 bytes)
196status:
197 description: The HTTP status from the APIC
198 returned: failure or debug
199 type: int
200 sample: 200
201url:
202 description: The HTTP url used for the request to the APIC
203 returned: failure or debug
204 type: str
205 sample: https://10.11.12.13/api/mo/uni/tn-production.json
206'''
207
208from ansible.module_utils.basic import AnsibleModule
209from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
210
211
212def main():
213 argument_spec = aci_argument_spec()
214 argument_spec.update(
215 filter=dict(type='str', aliases=['name', 'filter_name']), # Not required for querying all objects
216 tenant=dict(type='str', aliases=['tenant_name']), # Not required for querying all objects
217 description=dict(type='str', aliases=['descr']),
218 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
219 )
220
221 module = AnsibleModule(
222 argument_spec=argument_spec,
223 supports_check_mode=True,
224 required_if=[
225 ['state', 'absent', ['filter', 'tenant']],
226 ['state', 'present', ['filter', 'tenant']],
227 ],
228 )
229
230 filter_name = module.params['filter']
231 description = module.params['description']
232 state = module.params['state']
233 tenant = module.params['tenant']
234
235 aci = ACIModule(module)
236 aci.construct_url(
237 root_class=dict(
238 aci_class='fvTenant',
239 aci_rn='tn-{0}'.format(tenant),
240 module_object=tenant,
241 target_filter={'name': tenant},
242 ),
243 subclass_1=dict(
244 aci_class='vzFilter',
245 aci_rn='flt-{0}'.format(filter_name),
246 module_object=filter_name,
247 target_filter={'name': filter_name},
248 ),
249 )
250
251 aci.get_existing()
252
253 if state == 'present':
254 aci.payload(
255 aci_class='vzFilter',
256 class_config=dict(
257 name=filter_name,
258 descr=description,
259 ),
260 )
261
262 aci.get_diff(aci_class='vzFilter')
263
264 aci.post_config()
265
266 elif state == 'absent':
267 aci.delete_config()
268
269 aci.exit_json()
270
271
272if __name__ == "__main__":
273 main()