Repository: ansible/ansible

Issue:
infoblox dynamic inventory truncates extensible attributes
<!---
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
 - Bug Report


##### COMPONENT NAME
<!---
contrib/inventory/infoblox.py
-->

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.5.0 (devel_infoblox_exattrs 01091cddf6) last updated 2018/01/26 21:41:03 (GMT +200)
  config file = /home/clement/Documents/PROJECTS/ansible_env_setup/ansible/ansible.cfg
  configured module search path = ['/home/clement/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/clement/Documents/PROJECTS/ansible_env_setup/ansible/lib/ansible
  executable location = /home/clement/Documents/PROJECTS/ansible_env_setup/ansible/bin/ansible
  python version = 3.6.3 (default, Oct  9 2017, 12:07:10) [GCC 7.2.1 20170915 (Red Hat 7.2.1-2)]
```

##### 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.
-->
Fedora release 27 (Twenty Seven)
##### SUMMARY
<!--- Explain the problem briefly -->
As a network engineer, I need to be able to have the complete list of extensible attributes in my inventory and not a truncated list

The inventory produced by the infoblox inventory script is incomplete. Indeed, we should have the list of complete extensible attributes for each record, a minor bug overwrites the extensible attributes dictionary, the result is in the extensible attributes dictionary with only one entry.
##### 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 infoblox.py --list

<!--- Paste example playbooks or commands between quotes below -->

```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: <SERVER_IP>
  username: <USERNAME>
  password: <PASSWORD>

# 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_Service': 'CAMPUS', 'IN_Country': FR', 'IN_Owner': 'LAN'}, 

  # restrict returned hosts to a specified DNS view
  view: default
```

<!--- 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
"XXXX.XXXXX.com": {

                "extattrs": {

                    "IN_Vendor": "XXX",

                    "IN_Country": "XXX",

                    "IN_Service": "XXX",

                    "IN_Site": "XXX",

                    "IN_DeviceType": "XXX",

                    "IN_Owner": "XXX"

                },

                "view": "default"
```
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
```json
 "XXXX.XXXXX.com": {
        "extattrs": {
            "IN_Owner": "XXX"
        }, 
        "view": "default"
    }, 
```
<!--- Paste verbatim command output between quotes below -->
```

```



Discussion:

Resolving patch:
diff --git a/contrib/inventory/infoblox.py b/contrib/inventory/infoblox.py
--- a/contrib/inventory/infoblox.py
+++ b/contrib/inventory/infoblox.py
@@ -123,7 +123,7 @@ def main():
                     if key.startswith('ansible_'):
                         hostvars[name][key] = value
                     else:
-                        if 'extattrs' not in hostvars:
+                        if 'extattrs' not in hostvars[name]:
                             hostvars[name]['extattrs'] = {}
                         hostvars[name]['extattrs'][key] = value
 


Test patch: