Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNS Record Support for Bloxone Ansible v2 #46

Open
wants to merge 26 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9fcc451
Modules for DNS data
Tejashree-RS Nov 13, 2024
413ab0d
DNS A Record Support for Bloxone Ansible
Tejashree-RS Dec 2, 2024
462f0d4
deleted main.yml.bckp file
Tejashree-RS Dec 2, 2024
6a57e23
Merge branch 'v2' of github.com:infobloxopen/bloxone-ansible into dns…
Tejashree-RS Dec 17, 2024
63a4aa6
Removed dns_record and dns_record_info, added dns_a_record and dns_a_…
Tejashree-RS Dec 18, 2024
f4e7180
added A record changelog and setup_auth_zone_rmz; updated dns_record…
Tejashree-RS Dec 18, 2024
6837162
Deleted unused file
Tejashree-RS Dec 18, 2024
367a0dc
Restore setup_view file
Tejashree-RS Dec 18, 2024
d27ab24
Restored setup_view
Tejashree-RS Dec 18, 2024
21f18ce
Modified tasks in dns_a_record and dns_a_record_info
Tejashree-RS Dec 18, 2024
5789ea1
Removed extra lines
Tejashree-RS Dec 23, 2024
5da4699
Merge branch 'v2' of github.com:infobloxopen/bloxone-ansible into dns…
Tejashree-RS Dec 23, 2024
4377b79
addressed review comments
Tejashree-RS Jan 6, 2025
b3d8bae
addressed review comments
Tejashree-RS Jan 6, 2025
f248c12
Merge branch 'dns_records' of github.com:Tejashree-RS/bloxone-ansible…
Tejashree-RS Jan 6, 2025
0dfb09a
fixed indentation
Tejashree-RS Jan 6, 2025
2cd46d0
Modified find and update functions
Tejashree-RS Jan 9, 2025
939e08d
Removed HTML tags
Tejashree-RS Jan 9, 2025
1476303
added cleanup.yml for setup_auth_zone_rmz
Tejashree-RS Jan 10, 2025
d557e8e
Resolved merge conflicts
Tejashree-RS Jan 10, 2025
9abeae8
Removed setup_view directory from PR
Tejashree-RS Jan 10, 2025
e1c8dda
Addressed PR comments
Tejashree-RS Jan 10, 2025
a00709a
addressed PR comments
Tejashree-RS Jan 13, 2025
02bd9b3
Addressed PR comments
Tejashree-RS Jan 16, 2025
fcc9b4b
Merge branch 'v2' of github.com:infobloxopen/bloxone-ansible into dns…
Tejashree-RS Jan 16, 2025
6bde072
Fixed Documentation
Tejashree-RS Jan 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions changelogs/fragments/46-a-record.yml
mathewab marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

9 changes: 9 additions & 0 deletions changelogs/fragments/46-dns-record.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
deprecated_features:
- b1_a_record - is deprecated in favor of 'dns_record'.
- b1_a_record_gather - is deprecated in favor of 'dns_record_info'.
- b1_cname_record - is deprecated in favor of 'dns_record'.
- b1_cname_record_gather - is deprecated in favor of 'dns_record_info'.
- b1_ns_record - is deprecated in favor of 'dns_record'.
- b1_ns_record_gather - is deprecated in favor of 'dns_record_info'.
- b1_ptr_record - is deprecated in favor of 'dns_record'.
- b1_ptr_record_gather - is deprecated in favor of 'dns_record_info'.
40 changes: 19 additions & 21 deletions plugins/modules/dns_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
DOCUMENTATION = r"""
---
module: dns_record
mathewab marked this conversation as resolved.
Show resolved Hide resolved
short_description: Manage Record
short_description: Manage DNS Resource Record
description:
- Manage Record
version_added: 2.0.0
Expand Down Expand Up @@ -455,34 +455,33 @@ def find(self):
raise e
else:
if self.params["zone"] is not None:
filter = f"zone=='{self.params['zone']}' and type=='{self.params['type']}'"
if self.params["name_in_zone"] is not None:
filter = f"zone=='{self.params['zone']}' and type=='{self.params['type']}' and name_in_zone=='{self.params['name_in_zone']}'"
else:
filter = f"zone=='{self.params['zone']}' and type=='{self.params['type']}'"

elif self.params["absolute_name_spec"] is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as commented in the JIRA ticket, we can keep the zone,name_in_zone as the required combination. We can therefore remove absolute_name_spec and view checks from the find function. zone will have to be marked as required

filter = f"absolute_name_spec=='{self.params['absolute_name_spec']}' and type=='{self.params['type']}'"

else:
return self.fail_json(
msg="Either Zone or Name in Zone and Zone or Absolute Name Spec and View is required to create a record"
)

resp = RecordApi(self.client).list(filter=filter, inherit="full")

if len(resp.results) == 1:
return resp.results[0]
if len(resp.results) == 0:
return None

for i in resp.results:
if i["address"] != self.params["address"]:
resp.results.pop(i)

if len(resp.results) == 1:
return resp.results[0]
for index, val in resp.results:
if type == "A":
if getattr(val, "rdata")["address"] == self.params["rdata"]["address"]:
return resp.results[index]
if type == "PTR":
if getattr(val, "rdata")["dname"] == self.params["rdata"]["dname"]:
return resp.results[index]

if self.params["absolute_name_spec"] is not None:
for i in resp.results:
if i["view"] != self.params["view"]:
resp.results.pop(i)
for index, val in resp.results:
if getattr(val, "view") == self.params["view"]:
return resp.results[index]

if len(resp.results) == 1:
return resp.results[0]
Expand All @@ -503,11 +502,7 @@ def update(self):
return None

update_body = self.payload

if getattr(update_body, "view") is not None:
update_body = self.validate_readonly_on_update(self.existing, update_body, ["type", "zone", "view"])
else:
update_body = self.validate_readonly_on_update(self.existing, update_body, ["type", "zone"])
update_body = self.validate_readonly_on_update(self.existing, update_body, ["type", "zone"])
unasra marked this conversation as resolved.
Show resolved Hide resolved

resp = RecordApi(self.client).update(id=self.existing.id, body=update_body, inherit="full")
return resp.result.model_dump(by_alias=True, exclude_none=True)
Expand Down Expand Up @@ -590,6 +585,9 @@ def main():
argument_spec=module_args,
supports_check_mode=True,
required_if=[("state", "present", ["rdata", "type"])],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can add zone here, and remove the next three criteria. absolute_name_spec effectively becomes read only, since the API will give an error, but we don't have to mark it as read only in the module for now.

required_together=[("absolute_name_spec", "view")],
required_one_of=[("absolute_name_spec", "zone")],
mutually_exclusive=[("zone", "absolute_name_spec"), ("name_in_zone", "absolute_name_spec"), ("zone", "view")],
)

module.run_command()
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/dns_record_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
DOCUMENTATION = r"""
---
module: dns_record_info
short_description: Manage Record
short_description: Manage DNS Resource Record
description:
- Manage Record
version_added: 2.0.0
Expand Down
14 changes: 13 additions & 1 deletion tests/integration/targets/dns_a_record/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,17 @@
- a_record_info is not failed
- a_record_info.objects | length == 1
- a_record_info.objects[0].id == a_record.id
mathewab marked this conversation as resolved.
Show resolved Hide resolved
# create_ptr and check_rmz cannot be asserted here because the flags are not returned in the response of the call
- name: Get Information about the PTR Record created in the Reverse Mapping Zone
infoblox.bloxone.dns_record_info:
filters:
zone: "{{ rmz.id }}"
type: "PTR"
register: ptr_record_info
- assert:
that:
- ptr_record_info is not failed
- ptr_record_info.objects | length == 1
- ptr_record_info.objects[0].zone == rmz.id

- name: Create an A Record with Name in Zone and Zone
infoblox.bloxone.dns_record:
Expand Down Expand Up @@ -323,6 +333,7 @@
address: "15.0.0.0"
type: "A"
state: absent
ignore_errors : true

- name: "Delete the A Record"
infoblox.bloxone.dns_record:
Expand All @@ -332,6 +343,7 @@
address: "10.0.0.0"
type: "A"
state: absent
ignore_errors : true

- name: "Delete the Auth Zone"
ansible.builtin.include_role:
Expand Down
Loading