| 1 |
|
| 2 |
c |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
from __future__ import absolute_import, division, print_function |
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
DOCUMENTATION = ''' |
| 12 |
--- |
| 13 |
module: nios_nsgroup |
| 14 |
short_description: Configure Infoblox DNS Nameserver Authoritative Groups |
| 15 |
version_added: "1.0.0" |
| 16 |
extends_documentation_fragment: infoblox.nios_modules.nios |
| 17 |
author: |
| 18 |
- Erich Birngruber (@ebirn) |
| 19 |
- Sumit Jaiswal (@sjaiswal) |
| 20 |
description: |
| 21 |
- Adds and/or removes nameserver groups of type "Authoritative" form Infoblox NIOS servers. |
| 22 |
This module manages NIOS C(nsgroup) objects using the Infoblox. WAPI interface over REST. |
| 23 |
requirements: |
| 24 |
- infoblox_client |
| 25 |
notes: |
| 26 |
- This module supports C(check_mode). |
| 27 |
options: |
| 28 |
name: |
| 29 |
description: |
| 30 |
- Specifies the name of the NIOS nameserver group to be managed. |
| 31 |
required: true |
| 32 |
type: str |
| 33 |
grid_primary: |
| 34 |
description: |
| 35 |
- This host is to be used as primary server in this nameserver group. It must be a grid member. |
| 36 |
This option is required when setting I(use_external_primaries) to C(false). |
| 37 |
type: list |
| 38 |
elements: dict |
| 39 |
suboptions: |
| 40 |
name: |
| 41 |
description: |
| 42 |
- Provide the name of the grid member to identify the host. |
| 43 |
required: true |
| 44 |
type: str |
| 45 |
enable_preferred_primaries: |
| 46 |
description: |
| 47 |
- This flag represents whether the preferred_primaries field values of this member are used (see Infoblox WAPI docs). |
| 48 |
default: false |
| 49 |
type: bool |
| 50 |
grid_replicate: |
| 51 |
description: |
| 52 |
- Use DNS zone transfers if set to C(True) or ID Grid Replication if set to C(False). |
| 53 |
type: bool |
| 54 |
default: false |
| 55 |
lead: |
| 56 |
description: |
| 57 |
- This flag controls if the grid lead secondary nameserver performs zone transfers to non lead secondaries. |
| 58 |
type: bool |
| 59 |
default: false |
| 60 |
stealth: |
| 61 |
description: |
| 62 |
- Configure the external nameserver as stealth server (without NS record) in the zones. |
| 63 |
type: bool |
| 64 |
default: false |
| 65 |
preferred_primaries: |
| 66 |
description: |
| 67 |
- Provide a list of elements like in I(external_primaries) to set the precedence of preferred primary nameservers. |
| 68 |
type: list |
| 69 |
elements: dict |
| 70 |
suboptions: |
| 71 |
address: |
| 72 |
description: |
| 73 |
- Configures the IP address of the external nameserver |
| 74 |
required: true |
| 75 |
type: str |
| 76 |
name: |
| 77 |
description: |
| 78 |
- Set a label for the external nameserver |
| 79 |
required: true |
| 80 |
type: str |
| 81 |
stealth: |
| 82 |
description: |
| 83 |
- Configure the external nameserver as stealth server (without NS record) in the zones. |
| 84 |
type: bool |
| 85 |
default: false |
| 86 |
tsig_key_name: |
| 87 |
description: |
| 88 |
- Sets a label for the I(tsig_key) value |
| 89 |
required: true |
| 90 |
type: str |
| 91 |
tsig_key_alg: |
| 92 |
description: |
| 93 |
- Provides the algorithm used for the I(tsig_key) in use. |
| 94 |
choices: ['HMAC-MD5', 'HMAC-SHA256'] |
| 95 |
default: 'HMAC-MD5' |
| 96 |
type: str |
| 97 |
tsig_key: |
| 98 |
description: |
| 99 |
- Set a DNS TSIG key for the nameserver to secure zone transfers (AFXRs). |
| 100 |
type: str |
| 101 |
grid_secondaries: |
| 102 |
description: |
| 103 |
- Configures the list of grid member hosts that act as secondary nameservers. |
| 104 |
This option is required when setting I(use_external_primaries) to C(true). |
| 105 |
type: list |
| 106 |
elements: dict |
| 107 |
suboptions: |
| 108 |
name: |
| 109 |
description: |
| 110 |
- Provide the name of the grid member to identify the host. |
| 111 |
required: true |
| 112 |
type: str |
| 113 |
enable_preferred_primaries: |
| 114 |
description: |
| 115 |
- This flag represents whether the preferred_primaries field values of this member are used (see Infoblox WAPI docs). |
| 116 |
default: false |
| 117 |
type: bool |
| 118 |
grid_replicate: |
| 119 |
description: |
| 120 |
- Use DNS zone transfers if set to C(True) or ID Grid Replication if set to C(False) |
| 121 |
type: bool |
| 122 |
default: false |
| 123 |
lead: |
| 124 |
description: |
| 125 |
- This flag controls if the grid lead secondary nameserver performs zone transfers to non lead secondaries. |
| 126 |
type: bool |
| 127 |
default: false |
| 128 |
stealth: |
| 129 |
description: |
| 130 |
- Configure the external nameserver as stealth server (without NS record) in the zones. |
| 131 |
type: bool |
| 132 |
default: false |
| 133 |
preferred_primaries: |
| 134 |
description: |
| 135 |
- Provide a list of elements like in I(external_primaries) to set the precedence of preferred primary nameservers. |
| 136 |
type: list |
| 137 |
elements: dict |
| 138 |
suboptions: |
| 139 |
address: |
| 140 |
description: |
| 141 |
- Configures the IP address of the external nameserver |
| 142 |
required: true |
| 143 |
type: str |
| 144 |
name: |
| 145 |
description: |
| 146 |
- Set a label for the external nameserver |
| 147 |
required: true |
| 148 |
type: str |
| 149 |
stealth: |
| 150 |
description: |
| 151 |
- Configure the external nameserver as stealth server (without NS record) in the zones. |
| 152 |
type: bool |
| 153 |
default: false |
| 154 |
tsig_key_name: |
| 155 |
description: |
| 156 |
- Sets a label for the I(tsig_key) value |
| 157 |
required: true |
| 158 |
type: str |
| 159 |
tsig_key_alg: |
| 160 |
description: |
| 161 |
- Provides the algorithm used for the I(tsig_key) in use. |
| 162 |
choices: ['HMAC-MD5', 'HMAC-SHA256'] |
| 163 |
default: 'HMAC-MD5' |
| 164 |
type: str |
| 165 |
tsig_key: |
| 166 |
description: |
| 167 |
- Set a DNS TSIG key for the nameserver to secure zone transfers (AFXRs). |
| 168 |
type: str |
| 169 |
is_grid_default: |
| 170 |
description: |
| 171 |
- If set to C(True) this nsgroup will become the default nameserver group for new zones. |
| 172 |
type: bool |
| 173 |
default: false |
| 174 |
use_external_primary: |
| 175 |
description: |
| 176 |
- This flag controls whether the group is using an external primary nameserver. |
| 177 |
Note that modification of this field requires passing values for I(grid_secondaries) and I(external_primaries). |
| 178 |
type: bool |
| 179 |
default: false |
| 180 |
external_primaries: |
| 181 |
description: |
| 182 |
- Configures a list of external nameservers (non-members of the grid). |
| 183 |
This option is required when setting I(use_external_primaries) to C(true). |
| 184 |
type: list |
| 185 |
elements: dict |
| 186 |
suboptions: |
| 187 |
address: |
| 188 |
description: |
| 189 |
- Configures the IP address of the external nameserver |
| 190 |
required: true |
| 191 |
type: str |
| 192 |
name: |
| 193 |
description: |
| 194 |
- Set a label for the external nameserver |
| 195 |
required: true |
| 196 |
type: str |
| 197 |
stealth: |
| 198 |
description: |
| 199 |
- Configure the external nameserver as stealth server (without NS record) in the zones. |
| 200 |
type: bool |
| 201 |
default: false |
| 202 |
tsig_key_name: |
| 203 |
description: |
| 204 |
- Sets a label for the I(tsig_key) value |
| 205 |
required: true |
| 206 |
type: str |
| 207 |
tsig_key_alg: |
| 208 |
description: |
| 209 |
- Provides the algorithm used for the I(tsig_key) in use. |
| 210 |
choices: ['HMAC-MD5', 'HMAC-SHA256'] |
| 211 |
default: 'HMAC-MD5' |
| 212 |
type: str |
| 213 |
tsig_key: |
| 214 |
description: |
| 215 |
- Set a DNS TSIG key for the nameserver to secure zone transfers (AFXRs). |
| 216 |
type: str |
| 217 |
external_secondaries: |
| 218 |
description: |
| 219 |
- Allows to provide a list of external secondary nameservers, that are not members of the grid. |
| 220 |
type: list |
| 221 |
elements: dict |
| 222 |
suboptions: |
| 223 |
address: |
| 224 |
description: |
| 225 |
- Configures the IP address of the external nameserver |
| 226 |
required: true |
| 227 |
type: str |
| 228 |
name: |
| 229 |
description: |
| 230 |
- Set a label for the external nameserver |
| 231 |
required: true |
| 232 |
type: str |
| 233 |
stealth: |
| 234 |
description: |
| 235 |
- Configure the external nameserver as stealth server (without NS record) in the zones. |
| 236 |
type: bool |
| 237 |
default: false |
| 238 |
tsig_key_name: |
| 239 |
description: |
| 240 |
- Sets a label for the I(tsig_key) value |
| 241 |
required: true |
| 242 |
type: str |
| 243 |
tsig_key_alg: |
| 244 |
description: |
| 245 |
- Provides the algorithm used for the I(tsig_key) in use. |
| 246 |
choices: ['HMAC-MD5', 'HMAC-SHA256'] |
| 247 |
default: 'HMAC-MD5' |
| 248 |
type: str |
| 249 |
tsig_key: |
| 250 |
description: |
| 251 |
- Set a DNS TSIG key for the nameserver to secure zone transfers (AFXRs). |
| 252 |
type: str |
| 253 |
extattrs: |
| 254 |
description: |
| 255 |
- Allows for the configuration of Extensible Attributes on the |
| 256 |
instance of the object. This argument accepts a set of key / value |
| 257 |
pairs for configuration. |
| 258 |
type: str |
| 259 |
comment: |
| 260 |
description: |
| 261 |
- Configures a text string comment to be associated with the instance |
| 262 |
of this object. The provided text string will be configured on the |
| 263 |
object instance. |
| 264 |
type: str |
| 265 |
state: |
| 266 |
description: |
| 267 |
- Configures the intended state of the instance of the object on |
| 268 |
the NIOS server. When this value is set to C(present), the object |
| 269 |
is configured on the device and when this value is set to C(absent) |
| 270 |
the value is removed (if necessary) from the device. |
| 271 |
choices: [present, absent] |
| 272 |
default: present |
| 273 |
type: str |
| 274 |
''' |
| 275 |
|
| 276 |
EXAMPLES = ''' |
| 277 |
- name: Create simple infoblox nameserver group |
| 278 |
infoblox.nios_modules.nios_nsgroup: |
| 279 |
name: my-simple-group |
| 280 |
comment: "this is a simple nameserver group" |
| 281 |
grid_primary: |
| 282 |
- name: infoblox-test.example.com |
| 283 |
state: present |
| 284 |
provider: |
| 285 |
host: "{{ inventory_hostname_short }}" |
| 286 |
username: admin |
| 287 |
password: admin |
| 288 |
connection: local |
| 289 |
|
| 290 |
- name: Create infoblox nameserver group with external primaries |
| 291 |
infoblox.nios_modules.nios_nsgroup: |
| 292 |
name: my-example-group |
| 293 |
use_external_primary: true |
| 294 |
comment: "this is my example nameserver group" |
| 295 |
external_primaries: "{{ ext_nameservers }}" |
| 296 |
grid_secondaries: |
| 297 |
- name: infoblox-test.example.com |
| 298 |
lead: true |
| 299 |
preferred_primaries: "{{ ext_nameservers }}" |
| 300 |
state: present |
| 301 |
provider: |
| 302 |
host: "{{ inventory_hostname_short }}" |
| 303 |
username: admin |
| 304 |
password: admin |
| 305 |
connection: local |
| 306 |
|
| 307 |
- name: Delete infoblox nameserver group |
| 308 |
infoblox.nios_modules.nios_nsgroup: |
| 309 |
name: my-simple-group |
| 310 |
comment: "this is a simple nameserver group" |
| 311 |
grid_primary: |
| 312 |
- name: infoblox-test.example.com |
| 313 |
state: absent |
| 314 |
provider: |
| 315 |
host: "{{ inventory_hostname_short }}" |
| 316 |
username: admin |
| 317 |
password: admin |
| 318 |
connection: local |
| 319 |
''' |
| 320 |
|
| 321 |
RETURN = ''' # ''' |
| 322 |
|
| 323 |
from ansible.module_utils.basic import AnsibleModule |
| 324 |
from ..module_utils.api import WapiModule |
| 325 |
from ..module_utils.api import NIOS_NSGROUP |
| 326 |
from ..module_utils.api import normalize_ib_spec |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
def main(): |
| 345 |
'''entrypoint for module execution.''' |
| 346 |
argument_spec = dict( |
| 347 |
provider=dict(required=True), |
| 348 |
state=dict(default='present', choices=['present', 'absent']), |
| 349 |
) |
| 350 |
|
| 351 |
|
| 352 |
def clean_tsig(ext): |
| 353 |
if 'tsig_key' in ext and not ext['tsig_key']: |
| 354 |
del ext['tsig_key'] |
| 355 |
if 'tsig_key' not in ext and 'tsig_key_name' in ext and not ext['tsig_key_name']: |
| 356 |
del ext['tsig_key_name'] |
| 357 |
if 'tsig_key' not in ext and 'tsig_key_alg' in ext: |
| 358 |
del ext['tsig_key_alg'] |
| 359 |
|
| 360 |
def clean_grid_member(member): |
| 361 |
if member['preferred_primaries']: |
| 362 |
for ext in member['preferred_primaries']: |
| 363 |
clean_tsig(ext) |
| 364 |
if member['enable_preferred_primaries'] is False: |
| 365 |
del member['enable_preferred_primaries'] |
| 366 |
del member['preferred_primaries'] |
| 367 |
if member['lead'] is False: |
| 368 |
del member['lead'] |
| 369 |
if member['grid_replicate'] is False: |
| 370 |
del member['grid_replicate'] |
| 371 |
|
| 372 |
def ext_primaries_transform(module): |
| 373 |
if module.params['external_primaries']: |
| 374 |
for ext in module.params['external_primaries']: |
| 375 |
clean_tsig(ext) |
| 376 |
return module.params['external_primaries'] |
| 377 |
|
| 378 |
def ext_secondaries_transform(module): |
| 379 |
if module.params['external_secondaries']: |
| 380 |
for ext in module.params['external_secondaries']: |
| 381 |
clean_tsig(ext) |
| 382 |
return module.params['external_secondaries'] |
| 383 |
|
| 384 |
def grid_primary_preferred_transform(module): |
| 385 |
for member in module.params['grid_primary']: |
| 386 |
clean_grid_member(member) |
| 387 |
return module.params['grid_primary'] |
| 388 |
|
| 389 |
def grid_secondaries_preferred_primaries_transform(module): |
| 390 |
for member in module.params['grid_secondaries']: |
| 391 |
clean_grid_member(member) |
| 392 |
return module.params['grid_secondaries'] |
| 393 |
|
| 394 |
extserver_spec = dict( |
| 395 |
address=dict(required=True), |
| 396 |
name=dict(required=True), |
| 397 |
stealth=dict(type='bool', default=False), |
| 398 |
tsig_key=dict(no_log=True), |
| 399 |
tsig_key_alg=dict(choices=['HMAC-MD5', 'HMAC-SHA256'], default='HMAC-MD5'), |
| 400 |
tsig_key_name=dict(required=True) |
| 401 |
) |
| 402 |
|
| 403 |
memberserver_spec = dict( |
| 404 |
name=dict(required=True), |
| 405 |
enable_preferred_primaries=dict(type='bool', default=False), |
| 406 |
grid_replicate=dict(type='bool', default=False), |
| 407 |
lead=dict(type='bool', default=False), |
| 408 |
preferred_primaries=dict(type='list', elements='dict', options=extserver_spec, default=None), |
| 409 |
stealth=dict(type='bool', default=False), |
| 410 |
) |
| 411 |
|
| 412 |
ib_spec = dict( |
| 413 |
name=dict(required=True, ib_req=True), |
| 414 |
grid_primary=dict(type='list', elements='dict', options=memberserver_spec, |
| 415 |
transform=grid_primary_preferred_transform), |
| 416 |
grid_secondaries=dict(type='list', elements='dict', options=memberserver_spec, |
| 417 |
transform=grid_secondaries_preferred_primaries_transform), |
| 418 |
external_primaries=dict(type='list', elements='dict', options=extserver_spec, transform=ext_primaries_transform), |
| 419 |
external_secondaries=dict(type='list', elements='dict', options=extserver_spec, |
| 420 |
transform=ext_secondaries_transform), |
| 421 |
is_grid_default=dict(type='bool', default=False), |
| 422 |
use_external_primary=dict(type='bool', default=False), |
| 423 |
extattrs=dict(), |
| 424 |
comment=dict(), |
| 425 |
) |
| 426 |
|
| 427 |
argument_spec.update(normalize_ib_spec(ib_spec)) |
| 428 |
argument_spec.update(WapiModule.provider_spec) |
| 429 |
|
| 430 |
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) |
| 431 |
|
| 432 |
wapi = WapiModule(module) |
| 433 |
result = wapi.run(NIOS_NSGROUP, ib_spec) |
| 434 |
|
| 435 |
module.exit_json(**result) |
| 436 |
|
| 437 |
|
| 438 |
if __name__ == '__main__': |
| 439 |
main() |