Debian Codegraph @

ansible_collections/infoblox/nios_modules/plugins/modules/nios_member.py

raw symbols SCIP
1 #!/usr/bin/python
2 # Copyright (c) 2018-2019 Red Hat, Inc.
3 # Copyright (c) 2020 Infoblox, Inc.
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8
9 DOCUMENTATION = '''
10 ---
11 module: nios_member
12 author:
13 - "Krishna Vasudevan (@krisvasudevan)"
14 - "Matthew Dennett (@matthewdennett)"
15 short_description: Configure Infoblox NIOS members
16 version_added: "1.0.0"
17 description:
18 - Adds and/or removes Infoblox NIOS servers. This module manages NIOS C(member) objects using the Infoblox WAPI interface over REST.
19 requirements:
20 - infoblox-client
21 extends_documentation_fragment: infoblox.nios_modules.nios
22 notes:
23 - This module supports C(check_mode).
24 options:
25 host_name:
26 description:
27 - Specifies the host name of the member to either add or remove from
28 the NIOS instance. Users can also update the name as it is possible
29 to pass a dict containing I(new_name), I(old_name). See examples.
30 required: true
31 aliases:
32 - name
33 type: str
34 vip_setting:
35 description:
36 - Configures the network settings for the grid member.
37 suboptions:
38 address:
39 description:
40 - The IPv4 Address of the Grid Member
41 type: str
42 subnet_mask:
43 description:
44 - The subnet mask for the Grid Member
45 type: str
46 gateway:
47 description:
48 - The default gateway for the Grid Member
49 type: str
50 type: list
51 elements: dict
52 ipv6_setting:
53 description:
54 - Configures the IPv6 settings for the grid member.
55 suboptions:
56 virtual_ip:
57 description:
58 - The IPv6 Address of the Grid Member
59 type: str
60 cidr_prefix:
61 description:
62 - The IPv6 CIDR prefix for the Grid Member
63 type: int
64 gateway:
65 description:
66 - The gateway address for the Grid Member
67 type: str
68 type: list
69 elements: dict
70 config_addr_type:
71 description:
72 - Address configuration type (IPV4/IPV6/BOTH).
73 default: IPV4
74 type: str
75 comment:
76 description:
77 - A descriptive comment of the Grid member.
78 type: str
79 extattrs:
80 description:
81 - Extensible attributes associated with the object.
82 type: dict
83 enable_ha:
84 description:
85 - If set to True, the member has two physical nodes (HA pair).
86 default: False
87 type: bool
88 router_id:
89 description:
90 - Virtual router identifier. Provide this ID if "ha_enabled" is set to "true". This is a unique VRID number (from 1 to 255) for the local subnet.
91 type: int
92 lan2_enabled:
93 description:
94 - When set to "true", the LAN2 port is enabled as an independent port or as a port for failover purposes.
95 default: False
96 type: bool
97 lan2_port_setting:
98 description:
99 - Settings for the Grid member LAN2 port if 'lan2_enabled' is set to "true".
100 type: list
101 elements: dict
102 suboptions:
103 enabled:
104 description:
105 - If set to True, then it has its own IP settings.
106 type: bool
107 network_setting:
108 description:
109 - If the 'enable' field is set to True, this defines IPv4 network settings for LAN2.
110 suboptions:
111 address:
112 description:
113 - The IPv4 Address of LAN2
114 type: str
115 subnet_mask:
116 description:
117 - The subnet mask of LAN2
118 type: str
119 gateway:
120 description:
121 - The default gateway of LAN2
122 type: str
123 type: list
124 elements: dict
125 v6_network_setting:
126 description:
127 - If the 'enable' field is set to True, this defines IPv6 network settings for LAN2.
128 type: list
129 elements: dict
130 suboptions:
131 virtual_ip:
132 description:
133 - The IPv6 Address of LAN2
134 type: str
135 cidr_prefix:
136 description:
137 - The IPv6 CIDR prefix of LAN2
138 type: int
139 gateway:
140 description:
141 - The gateway address of LAN2
142 type: str
143 platform:
144 description:
145 - Configures the Hardware Platform.
146 default: INFOBLOX
147 type: str
148 node_info:
149 description:
150 - Configures the node information list with detailed status report on the operations of the Grid Member.
151 type: list
152 elements: dict
153 suboptions:
154 lan2_physical_setting:
155 description:
156 - Physical port settings for the LAN2 interface.
157 suboptions:
158 auto_port_setting_enabled:
159 description:
160 - Enable or disalbe the auto port setting.
161 type: bool
162 duplex:
163 description:
164 - The port duplex; if speed is 1000, duplex must be FULL.
165 type: str
166 speed:
167 description:
168 - The port speed; if speed is 1000, duplex is FULL.
169 type: str
170 type: list
171 elements: dict
172 lan_ha_port_setting:
173 description:
174 - LAN/HA port settings for the node.
175 type: list
176 elements: dict
177 suboptions:
178 ha_ip_address:
179 description:
180 - HA IP address.
181 type: str
182 ha_port_setting:
183 description:
184 - Physical port settings for the HA interface.
185 type: list
186 elements: dict
187 suboptions:
188 auto_port_setting_enabled:
189 description:
190 - Enable or disalbe the auto port setting.
191 type: bool
192 duplex:
193 description:
194 - The port duplex; if speed is 1000, duplex must be FULL.
195 type: str
196 speed:
197 description:
198 - The port speed; if speed is 1000, duplex is FULL.
199 type: str
200 lan_port_setting:
201 description:
202 - Physical port settings for the LAN interface.
203 type: list
204 elements: dict
205 suboptions:
206 auto_port_setting_enabled:
207 description:
208 - Enable or disalbe the auto port setting.
209 type: bool
210 duplex:
211 description:
212 - The port duplex; if speed is 1000, duplex must be FULL.
213 type: str
214 speed:
215 description:
216 - The port speed; if speed is 1000, duplex is FULL.
217 type: str
218 mgmt_ipv6addr:
219 description:
220 - Public IPv6 address for the LAN1 interface.
221 type: str
222 mgmt_lan:
223 description:
224 - Public IPv4 address for the LAN1 interface.
225 type: str
226 mgmt_network_setting:
227 description:
228 - Network settings for the MGMT port of the node.
229 type: list
230 elements: dict
231 suboptions:
232 address:
233 description:
234 - The IPv4 Address of MGMT
235 type: str
236 subnet_mask:
237 description:
238 - The subnet mask of MGMT
239 type: str
240 gateway:
241 description:
242 - The default gateway of MGMT
243 type: str
244 v6_mgmt_network_setting:
245 description:
246 - The network settings for the IPv6 MGMT port of the node.
247 type: list
248 elements: dict
249 suboptions:
250 virtual_ip:
251 description:
252 - The IPv6 Address of MGMT
253 type: str
254 cidr_prefix:
255 description:
256 - The IPv6 CIDR prefix of MGMT
257 type: int
258 gateway:
259 description:
260 - The gateway address of MGMT
261 type: str
262 mgmt_port_setting:
263 description:
264 - Settings for the member MGMT port.
265 type: list
266 elements: dict
267 suboptions:
268 enabled:
269 description:
270 - Determines if MGMT port settings should be enabled.
271 type: bool
272 security_access_enabled:
273 description:
274 - Determines if security access on the MGMT port is enabled or not.
275 type: bool
276 vpn_enabled:
277 description:
278 - Determines if VPN on the MGMT port is enabled or not.
279 type: bool
280 upgrade_group:
281 description:
282 - The name of the upgrade group to which this Grid member belongs.
283 default: Default
284 type: str
285 use_syslog_proxy_setting:
286 description:
287 - Use flag for external_syslog_server_enable , syslog_servers, syslog_proxy_setting, syslog_size.
288 type: bool
289 external_syslog_server_enable:
290 description:
291 - Determines if external syslog servers should be enabled.
292 type: bool
293 syslog_servers:
294 description:
295 - The list of external syslog servers.
296 type: list
297 elements: dict
298 suboptions:
299 address:
300 description:
301 - The server address.
302 type: str
303 category_list:
304 description:
305 - The list of all syslog logging categories.
306 type: list
307 elements: str
308 connection_type:
309 description:
310 - The connection type for communicating with this server.(STCP/TCP?UDP)
311 default: UDP
312 type: str
313 local_interface:
314 description:
315 - The local interface through which the appliance sends syslog messages to the syslog server.(ANY/LAN/MGMT)
316 default: ANY
317 type: str
318 message_node_id:
319 description:
320 - Identify the node in the syslog message. (HOSTNAME/IP_HOSTNAME/LAN/MGMT)
321 default: LAN
322 type: str
323 message_source:
324 description:
325 - The source of syslog messages to be sent to the external syslog server.
326 default: ANY
327 type: str
328 only_category_list:
329 description:
330 - The list of selected syslog logging categories. The appliance forwards syslog messages that belong to the selected categories.
331 type: bool
332 port:
333 description:
334 - The port this server listens on.
335 default: 514
336 type: int
337 severity:
338 description:
339 - The severity filter. The appliance sends log messages of the specified severity and above to the external syslog server.
340 default: DEBUG
341 type: str
342 pre_provisioning:
343 description:
344 - Pre-provisioning information.
345 type: list
346 elements: dict
347 suboptions:
348 hardware_info:
349 description:
350 - An array of structures that describe the hardware being pre-provisioned.
351 type: list
352 elements: dict
353 suboptions:
354 hwmodel:
355 description:
356 - Hardware model
357 type: str
358 hwtype:
359 description:
360 - Hardware type.
361 type: str
362 licenses:
363 description:
364 - An array of license types.
365 type: list
366 elements: str
367 create_token:
368 description:
369 - Flag for initiating a create token request for pre-provisioned members.
370 type: bool
371 default: False
372 master_candidate:
373 description:
374 - Configures the instance of this object to be enabled as a Grid Master
375 Candidate or a regular member node.
376 - True enables the member as a Master Candidate
377 type: bool
378 default: false
379 state:
380 description:
381 - Configures the intended state of the instance of the object on
382 the NIOS server. When this value is set to C(present), the object
383 is configured on the device and when this value is set to C(absent)
384 the value is removed (if necessary) from the device.
385 default: present
386 choices:
387 - present
388 - absent
389 type: str
390 '''
391
392 EXAMPLES = '''
393 - name: Add a member to the grid with IPv4 address
394 infoblox.nios_modules.nios_member:
395 host_name: member01.localdomain
396 vip_setting:
397 - address: 192.168.1.100
398 subnet_mask: 255.255.255.0
399 gateway: 192.168.1.1
400 config_addr_type: IPV4
401 platform: VNIOS
402 comment: "Created by Ansible"
403 state: present
404 provider:
405 host: "{{ inventory_hostname_short }}"
406 username: admin
407 password: admin
408 connection: local
409
410 - name: Add a Grid Master Candidate to the grid with IPv4 address
411 infoblox.nios_modules.nios_member:
412 host_name: member01.localdomain
413 master_candidate: true
414 vip_setting:
415 - address: 192.168.1.100
416 subnet_mask: 255.255.255.0
417 gateway: 192.168.1.1
418 config_addr_type: IPV4
419 platform: VNIOS
420 comment: "Created by Ansible"
421 state: present
422 provider:
423 host: "{{ inventory_hostname_short }}"
424 username: admin
425 password: admin
426 connection: local
427
428 - name: Update host name of member
429 infoblox.nios_modules.nios_member:
430 host_name: {old_name: block1.localdomain, new_name: member01.localdomain}
431 master_candidate: false
432 vip_setting:
433 - address: 120.0.0.25
434 subnet_mask: 255.255.255.0
435 gateway: 120.0.0.1
436 config_addr_type: IPV4
437 platform: VNIOS
438 state: present
439 provider:
440 host: "{{ inventory_hostname_short }}"
441 username: admin
442 password: admin
443 connection: local
444
445 - name: Add a HA member to the grid
446 infoblox.nios_modules.nios_member:
447 host_name: memberha.localdomain
448 vip_setting:
449 - address: 192.168.1.100
450 subnet_mask: 255.255.255.0
451 gateway: 192.168.1.1
452 config_addr_type: IPV4
453 platform: VNIOS
454 enable_ha: true
455 router_id: 150
456 node_info:
457 - lan_ha_port_setting:
458 - ha_ip_address: 192.168.1.70
459 mgmt_lan: 192.168.1.80
460 - lan_ha_port_setting:
461 - ha_ip_address: 192.168.1.71
462 mgmt_lan: 192.168.1.81
463 comment: "Created by Ansible"
464 state: present
465 provider:
466 host: "{{ inventory_hostname_short }}"
467 username: admin
468 password: admin
469 connection: local
470
471 - name: Update the member with pre-provisioning details specified
472 infoblox.nios_modules.nios_member:
473 name: member01.localdomain
474 pre_provisioning:
475 - hardware_info:
476 - hwmodel: IB-VM-820
477 hwtype: IB-VNIOS
478 licenses:
479 - dns
480 - dhcp
481 - enterprise
482 - vnios
483 comment: "Updated by Ansible"
484 state: present
485 provider:
486 host: "{{ inventory_hostname_short }}"
487 username: admin
488 password: admin
489 connection: local
490
491 - name: Remove the member
492 infoblox.nios_modules.nios_member:
493 name: member01.localdomain
494 state: absent
495 provider:
496 host: "{{ inventory_hostname_short }}"
497 username: admin
498 password: admin
499 connection: local
500 '''
501
502 RETURN = ''' # '''
503
504 from ansible.module_utils.basic import AnsibleModule
505 from ..module_utils.api import WapiModule
506 from ..module_utils.api import NIOS_MEMBER
507 from ..module_utils.api import normalize_ib_spec
508
509
510 def main():
511 ''' Main entry point for module execution
512 '''
513 ipv4_spec = dict(
514 address=dict(),
515 subnet_mask=dict(),
516 gateway=dict(),
517 )
518
519 ipv6_spec = dict(
520 virtual_ip=dict(),
521 cidr_prefix=dict(type='int'),
522 gateway=dict(),
523 )
524
525 port_spec = dict(
526 auto_port_setting_enabled=dict(type='bool'),
527 duplex=dict(),
528 speed=dict(),
529 )
530
531 lan2_port_spec = dict(
532 enabled=dict(type='bool'),
533 network_setting=dict(type='list', elements='dict', options=ipv4_spec),
534 v6_network_setting=dict(type='list', elements='dict', options=ipv6_spec),
535 )
536
537 ha_port_spec = dict(
538 ha_ip_address=dict(),
539 ha_port_setting=dict(type='list', elements='dict', options=port_spec),
540 lan_port_setting=dict(type='list', elements='dict', options=port_spec),
541 mgmt_lan=dict(),
542 mgmt_ipv6addr=dict(),
543 )
544
545 node_spec = dict(
546 lan2_physical_setting=dict(type='list', elements='dict', options=port_spec),
547 lan_ha_port_setting=dict(type='list', elements='dict', options=ha_port_spec),
548 mgmt_network_setting=dict(type='list', elements='dict', options=ipv4_spec),
549 v6_mgmt_network_setting=dict(type='list', elements='dict', options=ipv6_spec),
550 )
551
552 mgmt_port_spec = dict(
553 enabled=dict(type='bool'),
554 security_access_enabled=dict(type='bool'),
555 vpn_enabled=dict(type='bool'),
556 )
557
558 syslog_spec = dict(
559 address=dict(),
560 category_list=dict(type='list', elements='str'),
561 connection_type=dict(default='UDP'),
562 local_interface=dict(default='ANY'),
563 message_node_id=dict(default='LAN'),
564 message_source=dict(default='ANY'),
565 only_category_list=dict(type='bool'),
566 port=dict(type='int', default=514),
567 severity=dict(default='DEBUG'),
568 )
569
570 hw_spec = dict(
571 hwmodel=dict(),
572 hwtype=dict(),
573 )
574
575 pre_prov_spec = dict(
576 hardware_info=dict(type='list', elements='dict', options=hw_spec),
577 licenses=dict(type='list', elements='str'),
578 )
579
580 ib_spec = dict(
581 host_name=dict(required=True, aliases=['name'], ib_req=True),
582 vip_setting=dict(type='list', elements='dict', options=ipv4_spec),
583 ipv6_setting=dict(type='list', elements='dict', options=ipv6_spec),
584 config_addr_type=dict(default='IPV4'),
585 comment=dict(),
586 enable_ha=dict(type='bool', default=False),
587 router_id=dict(type='int'),
588 lan2_enabled=dict(type='bool', default=False),
589 lan2_port_setting=dict(type='list', elements='dict', options=lan2_port_spec),
590 platform=dict(default='INFOBLOX'),
591 node_info=dict(type='list', elements='dict', options=node_spec),
592 mgmt_port_setting=dict(type='list', elements='dict', options=mgmt_port_spec),
593 upgrade_group=dict(default='Default'),
594 use_syslog_proxy_setting=dict(type='bool'),
595 external_syslog_server_enable=dict(type='bool'),
596 syslog_servers=dict(type='list', elements='dict', options=syslog_spec),
597 pre_provisioning=dict(type='list', elements='dict', options=pre_prov_spec),
598 extattrs=dict(type='dict'),
599 create_token=dict(type='bool', default=False),
600 master_candidate=dict(type='bool', default=False)
601 )
602
603 argument_spec = dict(
604 provider=dict(required=True),
605 state=dict(default='present', choices=['present', 'absent'])
606 )
607
608 argument_spec.update(normalize_ib_spec(ib_spec))
609 argument_spec.update(WapiModule.provider_spec)
610
611 module = AnsibleModule(argument_spec=argument_spec,
612 supports_check_mode=True)
613
614 wapi = WapiModule(module)
615 result = wapi.run(NIOS_MEMBER, ib_spec)
616 module.exit_json(**result)
617
618
619 if __name__ == '__main__':
620 main()