Repository: ansible-collections/community.general

Issue:
nios_host_record DNS Bypass check is too strict 
**Summary**

`nios_host_record` doesn't allow creation of a host record with a non-default dns view specified when `configure_for_dns` is `false`. 

The `network` we target for our host record is in a network view that only has a non-default dns view assigned to it.

This limitation does not exist in Infoblox WAPI (tested in version 2.10), and creation via Infoblox Web UI (Add Host Wizard) works as well. So currently using the URI module as a workaround.

As NIOS/Infoblox does support multiple DNS views, and users can not always target the default, the module should not limit specifying non-default views.

**Issue Type**

Bug Report

**Component Name**

`nios_host_record`

**Ansible Version**

```
ansible 2.10.3
python version = 3.9.0 (v3.9.0:9cf6752276, Oct  5 2020, 11:29:23)
```

**Configuration**

```paste below

```


**OS / Environment**

Infoblox WAPI 2.10

**Steps To Reproduce**

```
- name: create host record
  community.general.nios_host_record:
    name: "my_host"
    ipv4:
      - address: "{{ host_ip }}"
        configure_for_dhcp: false
    state: present
    configure_for_dns: false
    dns_view: "default.my-custom-view"
    provider: "{{ nios_provider }}"
```

**Expected Results**

HTTP success response 201 "created".

**Actual Results**

```
fatal: [xxxxx]: FAILED! => changed=false
  invocation:
    module_args:
      aliases: null
      comment: null
      configure_for_dns: false
      dns_view: default.my-custom-view
      extattrs: null
      ipv4:
      - add: null
        address: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
        configure_for_dhcp: false
        ipv4addr: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
        mac: null
        remove: null
      ipv4addrs:
      - add: null
        address: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
        configure_for_dhcp: false
        ipv4addr: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
        mac: null
        remove: null
      ipv6addrs: null
      name: my_host
      provider:
        host: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
        http_pool_connections: 10
        http_pool_maxsize: 10
        http_request_timeout: 10
        max_results: 1000
        max_retries: 3
        password: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
        silent_ssl_warnings: true
        username: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
        wapi_version: '2.10'
      state: present
      ttl: null
      view: default.my-custom-view
  msg: DNS Bypass is not allowed if DNS view is set other than 'default'
```


Calling the endpoint via the URI module does work as expected:

```
- name: create host record
  uri:
    method: POST
    url: "https://{{ nios_host }}/wapi/v2.10/record:host"
    user: "{{ nios_user }}"
    password: "{{ nios_pass }}"
    body: >
      {
        "name": "my_host",
        "configure_for_dns": false,
        "ipv4addrs": [
            {
                "configure_for_dhcp": false,
                "ipv4addr": "{{ host_ip }}"
            }
        ],
        "view": "default.my-custom-view"
      }
    body_format: json
    status_code: 201
```


Discussion:
Files identified in the description:
* [`plugins/modules/net_tools/nios/nios_host_record.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/net_tools/nios/nios_host_record.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @NilashishC @Qalthos @danielmellado @ganeshrn @justjais @nerzhul @privateip @sganesh-infoblox @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/plugins/module_utils/net_tools/nios/api.py b/plugins/module_utils/net_tools/nios/api.py
--- a/plugins/module_utils/net_tools/nios/api.py
+++ b/plugins/module_utils/net_tools/nios/api.py
@@ -251,13 +251,10 @@ def run(self, ib_obj_type, ib_spec):
                 else:
                     proposed_object[key] = self.module.params[key]
 
-        # If configure_by_dns is set to False, then delete the default dns set in the param else throw exception
+        # If configure_by_dns is set to False and view is 'default', then delete the default dns
         if not proposed_object.get('configure_for_dns') and proposed_object.get('view') == 'default'\
                 and ib_obj_type == NIOS_HOST_RECORD:
             del proposed_object['view']
-        elif not proposed_object.get('configure_for_dns') and proposed_object.get('view') != 'default'\
-                and ib_obj_type == NIOS_HOST_RECORD:
-            self.module.fail_json(msg='DNS Bypass is not allowed if DNS view is set other than \'default\'')
 
         if ib_obj_ref:
             if len(ib_obj_ref) > 1:


Test patch: