Repository: ansible/ansible

Issue:
lookup plugin 'nios_next_ip': "'Connector' object has no attribute 'handle_exception'"

##### SUMMARY
I am trying to use the 'nios_next_ip' and I get "'Connector' object has no attribute 'handle_exception'"

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
nios_next_ip lookup plugin

##### ANSIBLE VERSION

```
$ ansible --version
ansible 2.5.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
```

##### CONFIGURATION

The `ansible-config dump --only-changed` returns nothing. No ANSIBLE_* environment variables) are set.

##### OS / ENVIRONMENT
<!--- Mention, BELOW THIS COMMENT, 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.-->

Ansible OS:

```
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:        18.04
Codename:       bionic
```

Managed OS:  

```
NIOS

Running:
8.1.6-360192
```

##### STEPS TO REPRODUCE

You will need an Infoblox system and  run this Playbook as `ansible-playbook add_a_record.yml`

```
---
- hosts: localhost
  connection: local

  tasks:

  - include_vars: vars/all

  - name: configure an ipv4 host record
    nios_host_record:
      name: test.example.com
      view: "MY DNS VIEW"
      ipv4:
        - address: "{{ lookup('nios_next_ip', '10.10.20.0/24', provider=provider ) }}"
      state: present
      comment: "Testing Infoblox Ansible integration"
      provider: "{{ provider }}"
```

vars/all:

```
provider:
  host: "10.10.10.10"
  username: niosadmin
  password: MySecretCombination
```

##### EXPECTED RESULTS

I expect the ansible tasks to finish without error, and the A record set with the next available IP

##### ACTUAL RESULTS

I get this when running `ansible-playbook -vvvv add_a_record.yml`

```
ansible-playbook 2.5.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
Parsed /etc/ansible/hosts inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/default.pyc

PLAYBOOK: add_a_record.yml ****************************************************************************************************************************************************************************************************************************
1 plays in add_a_record.yml

PLAY [localhost] **************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************************************************
task path: /root/arena/Playbooks/test/nios/add_a_record.yml:2
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/system/setup.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1533542152.1-258260034731858 `" && echo ansible-tmp-1533542152.1-258260034731858="` echo /root/.ansible/tmp/ansible-tmp-1533542152.1-258260034731858 `" ) && sleep 0'
<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-230032Hm1vC/tmpUdhQDN TO /root/.ansible/tmp/ansible-tmp-1533542152.1-258260034731858/setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1533542152.1-258260034731858/ /root/.ansible/tmp/ansible-tmp-1533542152.1-258260034731858/setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1533542152.1-258260034731858/setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1533542152.1-258260034731858/ > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers

TASK [include_vars] ***********************************************************************************************************************************************************************************************************************************
task path: /root/arena/Playbooks/test/nios/add_a_record.yml:7
ok: [localhost] => {
    "ansible_facts": {
        "provider": {
            "host": "10.10.10.10", 
            "password": "MySecretCombination", 
            "username": "niosadmin"
        }
    }, 
    "ansible_included_var_files": [
        "/root/arena/Playbooks/test/nios/vars/all"
    ], 
    "changed": false
}

TASK [configure an ipv4 host record] ******************************************************************************************************************************************************************************************************************
task path: /root/arena/Playbooks/test/nios/add_a_record.yml:9
fatal: [localhost]: FAILED! => {
    "msg": "An unhandled exception occurred while running the lookup plugin 'nios_next_ip'. Error was a <class 'ansible.errors.AnsibleError'>, original message: 'Connector' object has no attribute 'handle_exception'"
}
        to retry, use: --limit @/root/arena/Playbooks/test/nios/add_a_record.retry

PLAY RECAP ********************************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=1   
```



Discussion:
Files identified in the description:
* [lib/ansible/plugins/lookup/nios_next_ip.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/lookup/nios_next_ip.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 @gdpak @gundalow @privateip @rcarrillocruz @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
@theodotos Thanks for logging your observation, and I have tried to reproduce the behavior with the same playbook that you have tried and on ansible version `2.5.1`. But I wasn't able to reproduce the exception error situation.

Also, as you are using `nios lookup pluggin` to get the `next_available_ip` to assign the new `host_record` with respective IP you'll have to use indexing to input the `IP` to `ipv4:  address:` field, as `next_available_ip` returns the `list` of available IPs, for example in your case:

```
- name: configure an ipv4 host record
    nios_host_record:
      name: test.example.com
      view: "MY DNS VIEW"
      ipv4:
        - address: "{{ lookup('nios_next_ip', '10.10.20.0/24', provider=provider )[0] }}"
      state: present
      comment: "Testing Infoblox Ansible integration"
      provider: "{{ provider }}"
```
Here, I have given the index as `[0]` as you are retrieving only 1 `next_available_ip`, so the respective lookup will return you list with only single IP. For ref: retrieving multiple `next_available_ip` example:
`"{{ lookup('nios_next_ip', '10.10.20.0/24', num=3, provider=provider )[0] }}"`

Kindly, let me know if you are able to resolve the issue implementing the above.
Thanks for the suggestion @justjais. I tried indexing the first (and only) item in the list. Same result: 

```
# ansible-playbook --ask-vault-pass add_a_records-test.yml
Vault password: 

PLAY [localhost] **************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [localhost]

TASK [include_vars] ***********************************************************************************************************************************************************************************************
ok: [localhost]

TASK [include_vars] ***********************************************************************************************************************************************************************************************
ok: [localhost]

TASK [configure an ipv4 host record] ******************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "An unhandled exception occurred while running the lookup plugin 'nios_next_ip'. Error was a <class 'ansible.errors.AnsibleError'>, original message: 'Connector' object has no attribute 'handle_exception'"}
        to retry, use: --limit @/root/arena/Playbooks/ansible-infoblox/add_a_records-test.retry

PLAY RECAP ********************************************************************************************************************************************************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=1   
```

This is the playbook I'm using:

```
---
- hosts: localhost
  connection: local

  tasks:

  - include_vars: vars/all

  - name: configure an ipv4 host record
    nios_host_record:
      name: "mytest.example.com"
      view: "MY DNS VIEW"
      ipv4:
        - address: "{{ lookup('nios_next_ip', '10.10.10.0/24', provider=provider )[0] }}"
      state: present
      comment: "Testing Ansible to Infoblox nios_next_ip"
      provider: "{{ provider }}"
```
@theodotos Can you please run your play with `-vvvvv` tag and paste in the play run results.
Here it is:

```
ansible-playbook 2.5.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
Parsed /etc/ansible/hosts inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/default.pyc

PLAYBOOK: add_a_records-test.yml **********************************************************************************************************************************************************************************
1 plays in add_a_records-test.yml

PLAY [localhost] **************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
task path: /root/arena/Playbooks/ansible-infoblox/add_a_records-test.yml:2
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/basic.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/__init__.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/namespace.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/ansible_collector.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/default_collectors.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/_text.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/parsing/convert_bool.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/parsing/__init__.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/pycompat24.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/six/__init__.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/compat.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/timeout.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/collector.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/network/freebsd.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/virtual/openbsd.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/network/base.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/hardware/dragonfly.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/network/dragonfly.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/hardware/aix.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/network/aix.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/hardware/linux.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/platform.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/hardware/hpux.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/user.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/hardware/hurd.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/other/facter.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/virtual/sunos.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/network/hpux.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/distribution.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/virtual/freebsd.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/__init__.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/network/openbsd.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/network/darwin.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/network/linux.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/hardware/sunos.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/network/sunos.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/chroot.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/apparmor.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/hardware/openbsd.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/local.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/other/ohai.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/other/__init__.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/service_mgr.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/network/hurd.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/virtual/hpux.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/fips.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/selinux.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/virtual/__init__.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/pkg_mgr.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/dns.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/virtual/base.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/hardware/darwin.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/virtual/dragonfly.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/ssh_pub_keys.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/network/__init__.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/hardware/__init__.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/lsb.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/date_time.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/virtual/netbsd.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/hardware/base.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/cmdline.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/hardware/freebsd.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/network/netbsd.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/hardware/netbsd.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/caps.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/env.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/virtual/linux.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/system/python.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/network/generic_bsd.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/virtual/sysctl.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/utils.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/facts/sysctl.py
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/system/setup.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1533969889.23-73305902332128 `" && echo ansible-tmp-1533969889.23-73305902332128="` echo /root/.ansible/tmp/ansible-tmp-1533969889.23-73305902332128 `" ) && sleep 0'
<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-32708dGGTkE/tmpLqO6Ly TO /root/.ansible/tmp/ansible-tmp-1533969889.23-73305902332128/setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1533969889.23-73305902332128/ /root/.ansible/tmp/ansible-tmp-1533969889.23-73305902332128/setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1533969889.23-73305902332128/setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1533969889.23-73305902332128/ > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers

TASK [include_vars] ***********************************************************************************************************************************************************************************************
task path: /root/arena/Playbooks/ansible-infoblox/add_a_records-test.yml:7
looking for "vars/all" at "/root/arena/Playbooks/ansible-infoblox/vars/all"
Found a vault_id (default) in the vaulttext
We have a secret associated with vault id (default), will try to use to decrypt /root/arena/Playbooks/ansible-infoblox/vars/all
Trying to use vault secret=(<ansible.parsing.vault.PromptVaultSecret object at 0x7f971ccb8b10>) id=default to decrypt /root/arena/Playbooks/ansible-infoblox/vars/all
Trying secret <ansible.parsing.vault.PromptVaultSecret object at 0x7f971ccb8b10> for vault_id=default
Decrypt of "/root/arena/Playbooks/ansible-infoblox/vars/all" successful with secret=<ansible.parsing.vault.PromptVaultSecret object at 0x7f971ccb8b10> and vault_id=default
ok: [localhost] => {
    "ansible_facts": {
        "provider": {
            "host": "10.10.10.1",
            "password": "NotMyRealPass",
            "username": "niosadmin"
        }
    },
    "ansible_included_var_files": [
        "/root/arena/Playbooks/ansible-infoblox/vars/all"
    ],
    "changed": false
}

TASK [configure an ipv4 host record] ******************************************************************************************************************************************************************************
task path: /root/arena/Playbooks/ansible-infoblox/add_a_records-test.yml:9
fatal: [localhost]: FAILED! => {
    "msg": "An unhandled exception occurred while running the lookup plugin 'nios_next_ip'. Error was a <class 'ansible.errors.AnsibleError'>, original message: 'Connector' object has no attribute 'handle_exception'"
}
        to retry, use: --limit @/root/arena/Playbooks/ansible-infoblox/add_a_records-test.retry

PLAY RECAP ********************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=1  
```
@theodotos Thanks for logging the verbose output, seeing the output it seems that `nios` object is not able to make connection to `nios` server that you are providing to connect. As, I am getting the respective error: `Connector' object has no attribute 'handle_exception'` when I am unable to make connection to my `nios` server.
Can you please check if you are able to login to your `nios` server via browser and check if it's up and running and then try running the play. Hope it helps to resolve the same.
Yes server is up. I forgot to mention that if I maually add the IP Address everything works just fine. For example I use this playbook successfully:

```
---
- hosts: localhost
  connection: local

  tasks:

  - include_vars: vars/all

  - name: configure an ipv4 host record
    nios_host_record:
      name: "mytest.example.com"
      view: "MY DNS VIEW"
      ipv4:
        - address: 10.10.10.20
      state: present
      comment: "Testing Ansible to Infoblox nios_next_ip"
      provider: "{{ provider }}"
```

The problem happens when I try to use the 'nios_next_ip' lookup.
@theodotos ok that's strange, so are you able to run the `nios_next_ip` lookup as separate play and getting the list of next available IPs as output?
No I can run 'nios_host_record' setting the ipv4 address manually, which mean connection to the nios is good, but when I try the niox_next_ip lookup, inside nios_host_record, it fails.
@theodotos I meant was that are you able to run `niox_next_ip` lookup as a separate play. But anyways can you please edit one of the ansible file and run the play again, as that will give the exact error and help to resolve the issue:
1. Check the installation path of ansible package in your system. (_for ref: seeing the verbose output of your play it seems your ansible package is installed at path: `/usr/lib/python2.7/dist-packages/ansible`_)
2. File to edit: `/module_utils/net_tools/nios/api.py`. (if above path is right: _/usr/lib/python2.7/dist-packages/ansible/module_utils/net_tools/nios/api.py_)
3. Line to edit: **154** and class to edit `class WapiLookup(WapiBase):` in file `api.py`.

4. Paste `handle_exception` function inside respective class as:
```
class WapiLookup(WapiBase):
    def handle_exception(self, method_name, exc):
        raise
```
Save the changes, and try to run the playbook again with `-vvvv` parameter and paste in the output. 


OK this message is more descriptive but I am most certain that there are lots of available IPs in this network:

```
ansible-playbook 2.5.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
Parsed /etc/ansible/hosts inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/default.pyc

PLAYBOOK: add_a_records-test.yml **********************************************************************************************************************************************************************************
1 plays in add_a_records-test.yml

PLAY [localhost] **************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
task path: /root/arena/Playbooks/ansible-infoblox/add_a_records-test.yml:2
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/system/setup.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1534161873.71-59511619367827 `" && echo ansible-tmp-1534161873.71-59511619367827="` echo /root/.ansible/tmp/ansible-tmp-1534161873.71-59511619367827 `" ) && sleep 0'
<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-15913QZd78_/tmpqDIJaO TO /root/.ansible/tmp/ansible-tmp-1534161873.71-59511619367827/setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1534161873.71-59511619367827/ /root/.ansible/tmp/ansible-tmp-1534161873.71-59511619367827/setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1534161873.71-59511619367827/setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1534161873.71-59511619367827/ > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers

TASK [include_vars] ***********************************************************************************************************************************************************************************************
task path: /root/arena/Playbooks/ansible-infoblox/add_a_records-test.yml:7
Trying secret <ansible.parsing.vault.PromptVaultSecret object at 0x7f660cb3bb10> for vault_id=default
ok: [localhost] => {
    "ansible_facts": {
        "provider": {
            "host": "10.10.10.10",
            "password": "NotMyRealPass",
            "username": "niosadmin"
        }
    },
    "ansible_included_var_files": [
        "/root/arena/Playbooks/ansible-infoblox/vars/all"
    ],
    "changed": false
}

TASK [configure an ipv4 host record] ******************************************************************************************************************************************************************************
task path: /root/arena/Playbooks/ansible-infoblox/add_a_records-test.yml:9
fatal: [localhost]: FAILED! => {
    "msg": "An unhandled exception occurred while running the lookup plugin 'nios_next_ip'. Error was a <class 'ansible.errors.AnsibleError'>, original message: Error occurred during function's 'next_available_ip' call: ref network/ZG5zLm5ldHdvcmskMTAuMS4cMC4wLvIvLvA:10.10.10.0/24/MY%20NETWORKS: { \"Error\": \"AdmConDataError: None (IBDataError: IB.Data:Cannot find 1 available IP address(es) in this network.)\", \n  \"code\": \"Client.Ibap.Data\", \n  \"text\": \"Cannot find 1 available IP address(es) in this network.\"\n} [code 400]"
}
        to retry, use: --limit @/root/arena/Playbooks/ansible-infoblox/add_a_records-test.retry

PLAY RECAP ********************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=1  
```
@theodotos thanks for updating the result, coming to the exception it seems correct as this exception is being received from Nios server based on the wapi call that Ansible fires.
So, even if you try to fire direct POST call from any rest-client you should receive the same error.

I'll create a PR for handling the exception from lookup call as well. Hope it helps.

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
@@ -158,7 +158,11 @@ def _invoke_method(self, name, *args, **kwargs):
 
 class WapiLookup(WapiBase):
     ''' Implements WapiBase for lookup plugins '''
-    pass
+    def handle_exception(self, method_name, exc):
+        if ('text' in exc.response):
+            raise Exception(exc.response['text'])
+        else:
+            raise Exception(exc)
 
 
 class WapiInventory(WapiBase):


Test patch: