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