Repository: ansible/ansible

Issue:
INFOBLOX result set too large - no inventory returned - enable the max_results to be setted in the configuration file
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
 - Bug Report


##### COMPONENT NAME
<!---
Name of the module, plugin, task or feature
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path
-->
contrib/inventory/infoblox.py

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.5.0
  config file = /dns/development/ctrebuchet_sandbox/tower_playbooks/nac_compliance/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /dns/development/ctrebuchet_sandbox/zion_ansible/lib/python2.7/site-packages/ansible
  executable location = /dns/development/ctrebuchet_sandbox/zion_ansible/bin/ansible
  python version = 2.7.8 (default, Oct  9 2014, 10:48:46) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
Red Hat Enterprise Linux Server release 6.9 (Santiago)

##### SUMMARY
<!--- Explain the problem briefly -->
By default, the number of results is limited to 1000, passing the "max_results" parameter, this would raise this limitation.
Alas nothing was planned to pass this parameter in the yaml configuration file.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->
 python /dns/development/ctrebuchet_sandbox/ansible-devel/contrib/inventory/infoblox.py --list

```python
No handlers could be found for logger "infoblox_client.connector"
{
    "_meta": {
        "hostvars": {}
    }
}
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
```json

{
    "default": {
        "hosts": [
            "XXXXXXXXXXX.com",
           "XXXXXXXXXXX.com",
          "XXXXXXXXXXX.com",
          ......
]
}
 "_meta": {
        "hostvars": {blabla}
    }
}
```
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->

```python
No handlers could be found for logger "infoblox_client.connector"
{
    "_meta": {
        "hostvars": {}
    }
}
```

##### Quick FIX

- Add the max_results into the nios_provider_spec dict
- component: module_utils/net_tools/nios/api.py
- It would refer to '_max_results' option in WAPI
```yaml

---
# This file provides the configuration information for the Infoblox dynamic
# inventory script that is used to dynamically pull host information from NIOS.
# This file should be copied to /etc/ansible/infoblox.yaml in order for the
# dynamic script to find it.

# Sets the provider arguments for authenticating to the Infoblox server to
# retrieve inventory hosts.  Provider arguments can also be set using
# environment variables.  Supported environment variables all start with
# INFOBLOX_{{ name }}.  For instance, to set the host provider value, the
# environment variable would be INFOBLOX_HOST.
provider:
  host: XXXXXXXXXXX
  username: XXXXX
  password: XXXXX
  ssl_verify: False
  http_request_timeout: 120
  max_results: 10000 
# Filters allow the dynamic inventory script to restrict the set of hosts that
# are returned from the Infoblox server.
filters:
  # restrict returned hosts by extensible attributes
  extattrs: {"IN_DeviceType": "ACCESS", "IN_Country": "FR",  "IN_Service": "CAMPUS", "IN_Owner": "LAN" }


  # restrict returned hosts to a specified DNS view
  view: defaul
```
```python
nios_provider_spec = {
    'host': dict(),
    'username': dict(),
    'password': dict(no_log=True),
    'ssl_verify': dict(type='bool', default=False),
    'silent_ssl_warnings': dict(type='bool', default=True),
    'http_request_timeout': dict(type='int', default=10),
    'http_pool_connections': dict(type='int', default=10),
    'http_pool_maxsize': dict(type='int', default=10),
    'max_retries': dict(type='int', default=3),
    'wapi_version': dict(default='1.4'),
    'max_results': dict(type='int', 1000)
}

```



Discussion:
Files identified in the description:
* [contrib/inventory/infoblox.py](https://github.com/ansible/ansible/blob/devel/contrib/inventory/infoblox.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 @Qalthos @ganeshrn @gundalow @kedarX @privateip @rcarrillocruz @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/module_utils/net_tools/nios/api.py b/lib/ansible/module_utils/net_tools/nios/api.py
--- a/lib/ansible/module_utils/net_tools/nios/api.py
+++ b/lib/ansible/module_utils/net_tools/nios/api.py
@@ -50,7 +50,8 @@
     'http_pool_connections': dict(type='int', default=10),
     'http_pool_maxsize': dict(type='int', default=10),
     'max_retries': dict(type='int', default=3),
-    'wapi_version': dict(default='1.4')
+    'wapi_version': dict(default='1.4'),
+    'max_results': dict(type='int', default=1000)
 }
 
 
diff --git a/lib/ansible/utils/module_docs_fragments/nios.py b/lib/ansible/utils/module_docs_fragments/nios.py
--- a/lib/ansible/utils/module_docs_fragments/nios.py
+++ b/lib/ansible/utils/module_docs_fragments/nios.py
@@ -76,6 +76,15 @@ class ModuleDocFragment(object):
             variable.
         required: false
         default: 1.4
+      max_results:
+        description:
+          - Specifies the maximum number of objects to be returned,
+            if set to a negative number the appliance will return an error when the
+            number of returned objects would exceed the setting.
+          - Value can also be specified using C(INFOBLOX_MAX_RESULTS) environment
+            variable.
+        required: false
+        default: 1000
 notes:
   - "This module must be run locally, which can be achieved by specifying C(connection: local)."
 """


Test patch:
diff --git a/test/units/module_utils/net_tools/nios/test_api.py b/test/units/module_utils/net_tools/nios/test_api.py
--- a/test/units/module_utils/net_tools/nios/test_api.py
+++ b/test/units/module_utils/net_tools/nios/test_api.py
@@ -32,7 +32,7 @@ def tearDown(self):
     def test_get_provider_spec(self):
         provider_options = ['host', 'username', 'password', 'ssl_verify', 'silent_ssl_warnings',
                             'http_request_timeout', 'http_pool_connections',
-                            'http_pool_maxsize', 'max_retries', 'wapi_version']
+                            'http_pool_maxsize', 'max_retries', 'wapi_version', 'max_results']
         res = api.WapiBase.provider_spec
         self.assertIsNotNone(res)
         self.assertIn('provider', res)