Debian Codegraph @

ansible_collections/infoblox/nios_modules/plugins/modules/nios_zone.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_zone
12 author: "Peter Sprygada (@privateip)"
13 short_description: Configure Infoblox NIOS DNS zones
14 version_added: "1.0.0"
15 description:
16 - Adds and/or removes instances of DNS zone objects from
17 Infoblox NIOS servers. This module manages NIOS C(zone_auth) objects
18 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 fqdn:
26 description:
27 - Specifies the qualified domain name to either add or remove from
28 the NIOS instance based on the configured C(state) value.
29 required: true
30 aliases:
31 - name
32 type: str
33 view:
34 description:
35 - Configures the DNS view name for the configured resource. The
36 specified DNS zone must already exist on the running NIOS instance
37 prior to configuring zones.
38 default: default
39 aliases:
40 - dns_view
41 type: str
42 grid_primary:
43 description:
44 - Configures the grid primary servers for this zone.
45 suboptions:
46 name:
47 description:
48 - The name of the grid primary server
49 required: true
50 type: str
51 type: list
52 elements: dict
53 grid_secondaries:
54 description:
55 - Configures the grid secondary servers for this zone.
56 suboptions:
57 name:
58 description:
59 - The name of the grid secondary server
60 required: true
61 type: str
62 type: list
63 elements: dict
64 ns_group:
65 description:
66 - Configures the name server group for this zone. Name server group is
67 mutually exclusive with grid primary and grid secondaries.
68 type: str
69 restart_if_needed:
70 description:
71 - If set to true, causes the NIOS DNS service to restart and load the
72 new zone configuration.
73 type: bool
74 zone_format:
75 description:
76 - Create an authorative Reverse-Mapping Zone which is an area of network
77 space for which one or more name servers-primary and secondary-have the
78 responsibility to respond to address-to-name queries. It supports
79 reverse-mapping zones for both IPv4 and IPv6 addresses.
80 default: FORWARD
81 type: str
82 extattrs:
83 description:
84 - Allows for the configuration of Extensible Attributes on the
85 instance of the object. This argument accepts a set of key / value
86 pairs for configuration.
87 type: dict
88 comment:
89 description:
90 - Configures a text string comment to be associated with the instance
91 of this object. The provided text string will be configured on the
92 object instance.
93 type: str
94 state:
95 description:
96 - Configures the intended state of the instance of the object on
97 the NIOS server. When this value is set to C(present), the object
98 is configured on the device and when this value is set to C(absent)
99 the value is removed (if necessary) from the device.
100 default: present
101 choices:
102 - present
103 - absent
104 type: str
105 '''
106
107 EXAMPLES = '''
108 - name: Configure a zone on the system using grid primary and secondaries
109 infoblox.nios_modules.nios_zone:
110 name: ansible.com
111 grid_primary:
112 - name: gridprimary.grid.com
113 grid_secondaries:
114 - name: gridsecondary1.grid.com
115 - name: gridsecondary2.grid.com
116 restart_if_needed: true
117 state: present
118 provider:
119 host: "{{ inventory_hostname_short }}"
120 username: admin
121 password: admin
122 connection: local
123
124 - name: Configure a zone on the system using a name server group
125 infoblox.nios_modules.nios_zone:
126 name: ansible.com
127 ns_group: examplensg
128 restart_if_needed: true
129 state: present
130 provider:
131 host: "{{ inventory_hostname_short }}"
132 username: admin
133 password: admin
134 connection: local
135
136 - name: Configure a reverse mapping zone on the system using IPV4 zone format
137 infoblox.nios_modules.nios_zone:
138 name: 10.10.10.0/24
139 zone_format: IPV4
140 state: present
141 provider:
142 host: "{{ inventory_hostname_short }}"
143 username: admin
144 password: admin
145 connection: local
146
147 - name: Configure a reverse mapping zone on the system using IPV6 zone format
148 infoblox.nios_modules.nios_zone:
149 name: 100::1/128
150 zone_format: IPV6
151 state: present
152 provider:
153 host: "{{ inventory_hostname_short }}"
154 username: admin
155 password: admin
156 connection: local
157
158 - name: Update the comment and ext attributes for an existing zone
159 infoblox.nios_modules.nios_zone:
160 name: ansible.com
161 comment: this is an example comment
162 extattrs:
163 Site: west-dc
164 state: present
165 provider:
166 host: "{{ inventory_hostname_short }}"
167 username: admin
168 password: admin
169 connection: local
170
171 - name: Remove the dns zone
172 infoblox.nios_modules.nios_zone:
173 name: ansible.com
174 state: absent
175 provider:
176 host: "{{ inventory_hostname_short }}"
177 username: admin
178 password: admin
179 connection: local
180
181 - name: Remove the reverse mapping dns zone from the system with IPV4 zone format
182 infoblox.nios_modules.nios_zone:
183 name: 10.10.10.0/24
184 zone_format: IPV4
185 state: absent
186 provider:
187 host: "{{ inventory_hostname_short }}"
188 username: admin
189 password: admin
190 connection: local
191 '''
192
193 RETURN = ''' # '''
194
195 from ansible.module_utils.basic import AnsibleModule
196 from ..module_utils.api import WapiModule
197 from ..module_utils.api import NIOS_ZONE
198 from ..module_utils.api import normalize_ib_spec
199
200
201 def main():
202 ''' Main entry point for module execution
203 '''
204 grid_spec = dict(
205 name=dict(required=True),
206 )
207
208 ib_spec = dict(
209 fqdn=dict(required=True, aliases=['name'], ib_req=True, update=False),
210 zone_format=dict(default='FORWARD', ib_req=False),
211 view=dict(default='default', aliases=['dns_view'], ib_req=True),
212
213 grid_primary=dict(type='list', elements='dict', options=grid_spec),
214 grid_secondaries=dict(type='list', elements='dict', options=grid_spec),
215 ns_group=dict(),
216 restart_if_needed=dict(type='bool'),
217
218 extattrs=dict(type='dict'),
219 comment=dict()
220 )
221
222 argument_spec = dict(
223 provider=dict(required=True),
224 state=dict(default='present', choices=['present', 'absent'])
225 )
226
227 argument_spec.update(normalize_ib_spec(ib_spec))
228 argument_spec.update(WapiModule.provider_spec)
229
230 module = AnsibleModule(argument_spec=argument_spec,
231 supports_check_mode=True,
232 mutually_exclusive=[
233 ['ns_group', 'grid_primary'],
234 ['ns_group', 'grid_secondaries']
235 ])
236
237 wapi = WapiModule(module)
238 result = wapi.run(NIOS_ZONE, ib_spec)
239
240 module.exit_json(**result)
241
242
243 if __name__ == '__main__':
244 main()