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