Repository: ansible-collections/community.general

Issue:
nios_member fails in python 3 - RuntimeError: dictionary changed size during iteration
<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Also test if the latest release and devel branch are affected too -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
When using nios_member module with Python 3, the module fails with exception "RuntimeError: dictionary changed size during iteration"

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->
nios_member

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```paste below
ansible 2.10.3
  config file = None
  configured module search path = ['/home/coder/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/coder/ansible-venv/lib/python3.7/site-packages/ansible
  executable location = /home/coder/ansible-venv/bin/ansible
  python version = 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0]
```

##### CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```paste below

```

##### OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->
target device is Infoblox NIOS Release 8.2.6-371069 (64bit)

##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Add nios member in Master
  nios_member:
    host_name: "{{ inventory_hostname }}.mydomain"
    mgmt_port_setting:
      - enabled: yes
        security_access_enabled: no
        vpn_enabled: yes
    vip_setting: 
      - address: "{{ member_vip_address }}"
        subnet_mask: "{{member_vip_mask}}"
        gateway: "{{member_vip_gateway}}"
    config_addr_type: IPV4
    node_info:
      - mgmt_network_setting:
        - address: "{{ ansible_host }}"
          subnet_mask: "{{ member_mgt_mask }}"
          gateway: "{{ member_mgt_gw }}"
    platform: VNIOS
    comment: "Created by Ansible"
    state: present
    provider:
      host: "{{ nios_provider.host }}"
      username: "{{ nios_provider.username }}"
      password: "{{ nios_provider.password }}"
      wapi_version: "{{ nios_provider.wapi_version }}"
  connection: local
```

<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->
Member to be provision in Infoblox Grid

##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes -->
```paste below
TASK [provision : Add nios member in Master] **************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: RuntimeError: dictionary changed size during iteration
fatal: [infoblox-nios-dev]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/coder/.ansible/tmp/ansible-local-16480zh06vhpu/ansible-tmp-1608610731.5624626-17050-161708135985864/AnsiballZ_nios_member.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/home/coder/.ansible/tmp/ansible-local-16480zh06vhpu/ansible-tmp-1608610731.5624626-17050-161708135985864/AnsiballZ_nios_member.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/coder/.ansible/tmp/ansible-local-16480zh06vhpu/ansible-tmp-1608610731.5624626-17050-161708135985864/AnsiballZ_nios_member.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.nios_member', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.7/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.7/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib/python3.7/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_nios_member_payload_3z_j7ud5/ansible_nios_member_payload.zip/ansible_collections/community/general/plugins/modules/nios_member.py\", line 489, in <module>\n  File \"/tmp/ansible_nios_member_payload_3z_j7ud5/ansible_nios_member_payload.zip/ansible_collections/community/general/plugins/modules/nios_member.py\", line 484, in main\n  File \"/tmp/ansible_nios_member_payload_3z_j7ud5/ansible_nios_member_payload.zip/ansible_collections/community/general/plugins/module_utils/net_tools/nios/api.py\", line 288, in run\n  File \"/tmp/ansible_nios_member_payload_3z_j7ud5/ansible_nios_member_payload.zip/ansible_collections/community/general/plugins/module_utils/net_tools/nios/api.py\", line 156, in member_normalize\n  File \"/tmp/ansible_nios_member_payload_3z_j7ud5/ansible_nios_member_payload.zip/ansible_collections/community/general/plugins/module_utils/net_tools/nios/api.py\", line 148, in member_normalize\nRuntimeError: dictionary changed size during iteration\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

```



Discussion:
Files identified in the description:
* [`plugins/modules/net_tools/nios/nios_member.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/net_tools/nios/nios_member.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 @krisvasudevan @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
@@ -144,7 +144,7 @@ def member_normalize(member_spec):
                        'pre_provisioning', 'network_setting', 'v6_network_setting',
                        'ha_port_setting', 'lan_port_setting', 'lan2_physical_setting',
                        'lan_ha_port_setting', 'mgmt_network_setting', 'v6_mgmt_network_setting']
-    for key in member_spec.keys():
+    for key in list(member_spec.keys()):
         if key in member_elements and member_spec[key] is not None:
             member_spec[key] = member_spec[key][0]
         if isinstance(member_spec[key], dict):


Test patch: