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