1#!/usr/local/bin/python3.8 2# -*- coding: utf-8 -*- 3# Copyright (c) 2018 Red Hat, Inc. 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 9DOCUMENTATION = ''' 10--- 11module: nios_naptr_record 12author: "Blair Rampling (@brampling)" 13short_description: Configure Infoblox NIOS NAPTR records 14deprecated: 15 why: Please install the infoblox.nios_modules collection and use the corresponding module from it. 16 alternative: infoblox.nios_modules.nios_naptr_record 17 removed_in: 5.0.0 18description: 19 - Adds and/or removes instances of NAPTR record objects from 20 Infoblox NIOS servers. This module manages NIOS C(record:naptr) objects 21 using the Infoblox WAPI interface over REST. 22requirements: 23 - infoblox_client 24extends_documentation_fragment: 25- community.general.nios 26 27options: 28 name: 29 description: 30 - Specifies the fully qualified hostname to add or remove from 31 the system 32 required: true 33 type: str 34 view: 35 description: 36 - Sets the DNS view to associate this a record with. The DNS 37 view must already be configured on the system 38 default: default 39 aliases: 40 - dns_view 41 type: str 42 order: 43 description: 44 - Configures the order (0-65535) for this NAPTR record. This parameter 45 specifies the order in which the NAPTR rules are applied when 46 multiple rules are present. 47 type: int 48 preference: 49 description: 50 - Configures the preference (0-65535) for this NAPTR record. The 51 preference field determines the order NAPTR records are processed 52 when multiple records with the same order parameter are present. 53 type: int 54 replacement: 55 description: 56 - Configures the replacement field for this NAPTR record. 57 For nonterminal NAPTR records, this field specifies the 58 next domain name to look up. 59 type: str 60 services: 61 description: 62 - Configures the services field (128 characters maximum) for this 63 NAPTR record. The services field contains protocol and service 64 identifiers, such as "http+E2U" or "SIPS+D2T". 65 required: false 66 type: str 67 flags: 68 description: 69 - Configures the flags field for this NAPTR record. These control the 70 interpretation of the fields for an NAPTR record object. Supported 71 values for the flags field are "U", "S", "P" and "A". 72 required: false 73 type: str 74 regexp: 75 description: 76 - Configures the regexp field for this NAPTR record. This is the 77 regular expression-based rewriting rule of the NAPTR record. This 78 should be a POSIX compliant regular expression, including the 79 substitution rule and flags. Refer to RFC 2915 for the field syntax 80 details. 81 required: false 82 type: str 83 ttl: 84 description: 85 - Configures the TTL to be associated with this NAPTR record 86 type: int 87 extattrs: 88 description: 89 - Allows for the configuration of Extensible Attributes on the 90 instance of the object. This argument accepts a set of key / value 91 pairs for configuration. 92 type: dict 93 comment: 94 description: 95 - Configures a text string comment to be associated with the instance 96 of this object. The provided text string will be configured on the 97 object instance. 98 type: str 99 state: 100 description: 101 - Configures the intended state of the instance of the object on 102 the NIOS server. When this value is set to C(present), the object 103 is configured on the device and when this value is set to C(absent) 104 the value is removed (if necessary) from the device. 105 default: present 106 choices: 107 - present 108 - absent 109 type: str 110''' 111 112EXAMPLES = ''' 113- name: Configure a NAPTR record 114 community.general.nios_naptr_record: 115 name: '*.subscriber-100.ansiblezone.com' 116 order: 1000 117 preference: 10 118 replacement: replacement1.network.ansiblezone.com 119 state: present 120 provider: 121 host: "{{ inventory_hostname_short }}" 122 username: admin 123 password: admin 124 connection: local 125 126- name: Add a comment to an existing NAPTR record 127 community.general.nios_naptr_record: 128 name: '*.subscriber-100.ansiblezone.com' 129 order: 1000 130 preference: 10 131 replacement: replacement1.network.ansiblezone.com 132 comment: this is a test comment 133 state: present 134 provider: 135 host: "{{ inventory_hostname_short }}" 136 username: admin 137 password: admin 138 connection: local 139 140- name: Remove a NAPTR record from the system 141 community.general.nios_naptr_record: 142 name: '*.subscriber-100.ansiblezone.com' 143 order: 1000 144 preference: 10 145 replacement: replacement1.network.ansiblezone.com 146 state: absent 147 provider: 148 host: "{{ inventory_hostname_short }}" 149 username: admin 150 password: admin 151 connection: local 152''' 153 154RETURN = ''' # ''' 155 156from ansible.module_utils.basic import AnsibleModule 157from ansible_collections.community.general.plugins.module_utils.net_tools.nios.api import WapiModule 158from ansible_collections.community.general.plugins.module_utils.net_tools.nios.api import normalize_ib_spec 159 160 161def main(): 162 ''' Main entry point for module execution 163 ''' 164 165 ib_spec = dict( 166 name=dict(required=True, ib_req=True), 167 view=dict(default='default', aliases=['dns_view'], ib_req=True), 168 169 order=dict(type='int', ib_req=True), 170 preference=dict(type='int', ib_req=True), 171 replacement=dict(ib_req=True), 172 services=dict(), 173 flags=dict(), 174 regexp=dict(), 175 176 ttl=dict(type='int'), 177 178 extattrs=dict(type='dict'), 179 comment=dict(), 180 ) 181 182 argument_spec = dict( 183 provider=dict(required=True), 184 state=dict(default='present', choices=['present', 'absent']) 185 ) 186 187 argument_spec.update(normalize_ib_spec(ib_spec)) 188 argument_spec.update(WapiModule.provider_spec) 189 190 module = AnsibleModule(argument_spec=argument_spec, 191 supports_check_mode=True) 192 193 wapi = WapiModule(module) 194 result = wapi.run('record:naptr', ib_spec) 195 196 module.exit_json(**result) 197 198 199if __name__ == '__main__': 200 main() 201