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_maintenance_group.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 = {
10 'metadata_version': '1.1',
11 'status': ['preview'],
12 'supported_by': 'community'
13}
14
15DOCUMENTATION = '''
16module: aci_maintenance_group
17short_description: This creates an ACI maintenance group
18version_added: "2.8"
19notes:
20 - a maintenance policy (aci_maintenance_policy must be created prior to creating an aci maintenance group
21description:
22 - This modules creates an ACI maintenance group
23options:
24 group:
25 description:
26 - This is the name of the group
27 required: true
28 policy:
29 description:
30 - This is the name of the policy that was created using aci_maintenance_policy
31 required: true
32 state:
33 description:
34 - Use C(present) or C(absent) for adding or removing.
35 - Use C(query) for listing an object or multiple objects.
36 default: present
37 choices: ['absent', 'present', 'query']
38extends_documentation_fragment:
39 - aci
40author:
41 - Steven Gerhart (@sgerhart)
42'''
43
44EXAMPLES = '''
45- name: maintenance group
46 aci_maintenance_group:
47 host: "{{ inventory_hostname }}"
48 username: "{{ user }}"
49 password: "{{ pass }}"
50 validate_certs: no
51 group: maintenancegrp1
52 policy: maintenancePol1
53 state: present
54'''
55
56RETURN = '''
57current:
58 description: The existing configuration from the APIC after the module has finished
59 returned: success
60 type: list
61 sample:
62 [
63 {
64 "fvTenant": {
65 "attributes": {
66 "descr": "Production environment",
67 "dn": "uni/tn-production",
68 "name": "production",
69 "nameAlias": "",
70 "ownerKey": "",
71 "ownerTag": ""
72 }
73 }
74 }
75 ]
76error:
77 description: The error information as returned from the APIC
78 returned: failure
79 type: dict
80 sample:
81 {
82 "code": "122",
83 "text": "unknown managed object class foo"
84 }
85raw:
86 description: The raw output returned by the APIC REST API (xml or json)
87 returned: parse error
88 type: str
89 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
90sent:
91 description: The actual/minimal configuration pushed to the APIC
92 returned: info
93 type: list
94 sample:
95 {
96 "fvTenant": {
97 "attributes": {
98 "descr": "Production environment"
99 }
100 }
101 }
102previous:
103 description: The original configuration from the APIC before the module has started
104 returned: info
105 type: list
106 sample:
107 [
108 {
109 "fvTenant": {
110 "attributes": {
111 "descr": "Production",
112 "dn": "uni/tn-production",
113 "name": "production",
114 "nameAlias": "",
115 "ownerKey": "",
116 "ownerTag": ""
117 }
118 }
119 }
120 ]
121proposed:
122 description: The assembled configuration from the user-provided parameters
123 returned: info
124 type: dict
125 sample:
126 {
127 "fvTenant": {
128 "attributes": {
129 "descr": "Production environment",
130 "name": "production"
131 }
132 }
133 }
134filter_string:
135 description: The filter string used for the request
136 returned: failure or debug
137 type: str
138 sample: ?rsp-prop-include=config-only
139method:
140 description: The HTTP method used for the request to the APIC
141 returned: failure or debug
142 type: str
143 sample: POST
144response:
145 description: The HTTP response from the APIC
146 returned: failure or debug
147 type: str
148 sample: OK (30 bytes)
149status:
150 description: The HTTP status from the APIC
151 returned: failure or debug
152 type: int
153 sample: 200
154url:
155 description: The HTTP url used for the request to the APIC
156 returned: failure or debug
157 type: str
158 sample: https://10.11.12.13/api/mo/uni/tn-production.json
159'''
160
161from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
162from ansible.module_utils.basic import AnsibleModule
163
164
165def main():
166 argument_spec = aci_argument_spec()
167 argument_spec.update(
168 group=dict(type='str'), # Not required for querying all objects
169 policy=dict(type='str'), # Not required for querying all objects
170 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
171 )
172
173 module = AnsibleModule(
174 argument_spec=argument_spec,
175 supports_check_mode=True,
176 required_if=[
177 ['state', 'absent', ['group']],
178 ['state', 'present', ['group']],
179 ],
180 )
181
182 state = module.params['state']
183 group = module.params['group']
184 policy = module.params['policy']
185
186 aci = ACIModule(module)
187 aci.construct_url(
188 root_class=dict(
189 aci_class='maintMaintGrp',
190 aci_rn='fabric/maintgrp-{0}'.format(group),
191 target_filter={'name': group},
192 module_object=group,
193 ),
194 child_classes=['maintRsMgrpp'],
195 )
196
197 aci.get_existing()
198
199 if state == 'present':
200 aci.payload(
201 aci_class='maintMaintGrp',
202 class_config=dict(
203 name=group,
204 ),
205 child_configs=[
206 dict(
207 maintRsMgrpp=dict(
208 attributes=dict(
209 tnMaintMaintPName=policy,
210 ),
211 ),
212 ),
213 ],
214
215 )
216
217 aci.get_diff(aci_class='maintMaintGrp')
218
219 aci.post_config()
220
221 elif state == 'absent':
222 aci.delete_config()
223
224 aci.exit_json()
225
226
227if __name__ == "__main__":
228 main()