# Buggy code
def __init__(self):
    """
    Initialize the Ontap IfGrp class
    """
    self.argument_spec = netapp_utils.na_ontap_host_argument_spec()
    self.argument_spec.update(
        dict(
            state=dict(
                required=False, choices=["present", "absent"], default="present"
            ),
            distribution_function=dict(
                required=False, type="str", choices=["mac", "ip", "sequential", "port"]
            ),
            name=dict(required=True, type="str"),
            mode=dict(required=False, type="str"),
            node=dict(required=True, type="str"),
            port=dict(required=False, type="str"),
        )
    )

    self.module = AnsibleModule(
        argument_spec=self.argument_spec,
        required_if=[("state", "present", ["distribution_function", "mode"])],
        supports_check_mode=True,
    )

    parameters = self.module.params

    # set up state variables
    self.state = parameters["state"]
    self.distribution_function = parameters["distribution_function"]
    self.name = parameters["name"]
    self.mode = parameters["mode"]
    self.node = parameters["node"]
    self.port = parameters["port"]

    if HAS_NETAPP_LIB is False:
        self.module.fail_json(msg="the python NetApp-Lib module is required")
    else:
        self.server = netapp_utils.setup_na_ontap_zapi(module=self.module)
    return


# Traceback (netapp_lib.api.zapi.zapi.NaApiError)
ansible-playbook -i netapp-inventory config.yml -vvv
ansible-playbook 2.6.1
config file = None
configured module search path = [u'/home/fgzx6022/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /home/fgzx6022/Work/python-env/ansible2.6/local/lib/python2.7/site-packages/ansible
executable location = /home/fgzx6022/Work/python-env/ansible2.6/bin/ansible-playbook
python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
No config file found; using defaults
Parsed /home/fgzx6022/Work/ansible-netapp/netapp-inventory inventory source with ini plugin

PLAYBOOK: config.yml ***********************************************************************************************************************
1 plays in config.yml

PLAY [cdot_9] ******************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************
task path: /home/fgzx6022/Work/ansible-netapp/config.yml:1
<cloud-nas-y00n-prd.cloud.620nm.net> ESTABLISH LOCAL CONNECTION FOR USER: fgzx6022
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c 'echo ~fgzx6022 &amp;&amp; sleep 0'
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908092.55-277150875000599 `" &amp;&amp; echo ansible-tmp-1531908092.55-277150875000599="` echo /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908092.55-277150875000599 `" ) &amp;&amp; sleep 0'
Using module file /home/fgzx6022/Work/python-env/ansible2.6/local/lib/python2.7/site-packages/ansible/modules/system/setup.py
<cloud-nas-y00n-prd.cloud.620nm.net> PUT /home/fgzx6022/.ansible/tmp/ansible-local-28921IRjFWh/tmp9gDqI_ TO /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908092.55-277150875000599/setup.py
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c 'chmod u+x /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908092.55-277150875000599/ /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908092.55-277150875000599/setup.py &amp;&amp; sleep 0'
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c '/usr/bin/python /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908092.55-277150875000599/setup.py &amp;&amp; sleep 0'
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c 'rm -f -r /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908092.55-277150875000599/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
ok: [cloud-nas-y00n-prd.cloud.620nm.net]
META: ran handlers

TASK [network : create LACP Data interface group] ******************************************************************************************
task path: /home/fgzx6022/Work/ansible-netapp/roles/network/tasks/main.yml:1
<cloud-nas-y00n-prd.cloud.620nm.net> ESTABLISH LOCAL CONNECTION FOR USER: fgzx6022
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c 'echo ~fgzx6022 &amp;&amp; sleep 0'
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908094.16-128445494609484 `" &amp;&amp; echo ansible-tmp-1531908094.16-128445494609484="` echo /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908094.16-128445494609484 `" ) &amp;&amp; sleep 0'
Using module file /home/fgzx6022/Work/python-env/ansible2.6/local/lib/python2.7/site-packages/ansible/modules/storage/netapp/na_ontap_net_ifgrp.py
<cloud-nas-y00n-prd.cloud.620nm.net> PUT /home/fgzx6022/.ansible/tmp/ansible-local-28921IRjFWh/tmpqfg6da TO /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908094.16-128445494609484/na_ontap_net_ifgrp.py
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c 'chmod u+x /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908094.16-128445494609484/ /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908094.16-128445494609484/na_ontap_net_ifgrp.py &amp;&amp; sleep 0'
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c '/usr/bin/python /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908094.16-128445494609484/na_ontap_net_ifgrp.py &amp;&amp; sleep 0'
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c 'rm -f -r /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908094.16-128445494609484/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
ok: [cloud-nas-y00n-prd.cloud.620nm.net] => (item=[u'cloud-nas-y01n-prd', u'e0c']) => {
"changed": false,
"invocation": {
"module_args": {
"distribution_function": "ip",
"hostname": "cloud-nas-y00n-prd.cloud.620nm.net",
"https": false,
"mode": "multimode_lacp",
"name": "a0a",
"node": "cloud-nas-y01n-prd",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"port": "e0c",
"state": "present",
"username": "admin"
}
},
"item": [
"cloud-nas-y01n-prd",
"e0c"
]
}
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c 'echo ~fgzx6022 &amp;&amp; sleep 0'
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908095.44-221329292655805 `" &amp;&amp; echo ansible-tmp-1531908095.44-221329292655805="` echo /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908095.44-221329292655805 `" ) &amp;&amp; sleep 0'
Using module file /home/fgzx6022/Work/python-env/ansible2.6/local/lib/python2.7/site-packages/ansible/modules/storage/netapp/na_ontap_net_ifgrp.py
<cloud-nas-y00n-prd.cloud.620nm.net> PUT /home/fgzx6022/.ansible/tmp/ansible-local-28921IRjFWh/tmpgOlad4 TO /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908095.44-221329292655805/na_ontap_net_ifgrp.py
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c 'chmod u+x /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908095.44-221329292655805/ /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908095.44-221329292655805/na_ontap_net_ifgrp.py &amp;&amp; sleep 0'
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c '/usr/bin/python /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908095.44-221329292655805/na_ontap_net_ifgrp.py &amp;&amp; sleep 0'
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c 'rm -f -r /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908095.44-221329292655805/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
ok: [cloud-nas-y00n-prd.cloud.620nm.net] => (item=[u'cloud-nas-y01n-prd', u'e0d']) => {
"changed": false,
"invocation": {
"module_args": {
"distribution_function": "ip",
"hostname": "cloud-nas-y00n-prd.cloud.620nm.net",
"https": false,
"mode": "multimode_lacp",
"name": "a0a",
"node": "cloud-nas-y01n-prd",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"port": "e0d",
"state": "present",
"username": "admin"
}
},
"item": [
"cloud-nas-y01n-prd",
"e0d"
]
}
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c 'echo ~fgzx6022 &amp;&amp; sleep 0'
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908096.45-128927256535041 `" &amp;&amp; echo ansible-tmp-1531908096.45-128927256535041="` echo /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908096.45-128927256535041 `" ) &amp;&amp; sleep 0'
Using module file /home/fgzx6022/Work/python-env/ansible2.6/local/lib/python2.7/site-packages/ansible/modules/storage/netapp/na_ontap_net_ifgrp.py
<cloud-nas-y00n-prd.cloud.620nm.net> PUT /home/fgzx6022/.ansible/tmp/ansible-local-28921IRjFWh/tmpA1qXmY TO /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908096.45-128927256535041/na_ontap_net_ifgrp.py
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c 'chmod u+x /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908096.45-128927256535041/ /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908096.45-128927256535041/na_ontap_net_ifgrp.py &amp;&amp; sleep 0'
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c '/usr/bin/python /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908096.45-128927256535041/na_ontap_net_ifgrp.py &amp;&amp; sleep 0'
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c 'rm -f -r /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908096.45-128927256535041/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_VD77M_/ansible_module_na_ontap_net_ifgrp.py", line 324, in <module>
main()
File "/tmp/ansible_VD77M_/ansible_module_na_ontap_net_ifgrp.py", line 320, in main
obj.apply()
File "/tmp/ansible_VD77M_/ansible_module_na_ontap_net_ifgrp.py", line 276, in apply
ifgrp_ports_detail = self.get_if_grp_ports()
File "/tmp/ansible_VD77M_/ansible_module_na_ontap_net_ifgrp.py", line 185, in get_if_grp_ports
result = self.server.invoke_successfully(if_group_iter, True)
File "/usr/local/lib/python2.7/dist-packages/netapp_lib/api/zapi/zapi.py", line 294, in invoke_successfully
raise NaApiError(code, msg)
netapp_lib.api.zapi.zapi.NaApiError: NetApp API failed. Reason - 15661:entry doesn't exist

failed: [cloud-nas-y00n-prd.cloud.620nm.net] (item=[u'cloud-nas-y02n-prd', u'e0c']) => {
"changed": false,
"item": [
"cloud-nas-y02n-prd",
"e0c"
],
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_VD77M_/ansible_module_na_ontap_net_ifgrp.py\", line 324, in <module>\n    main()\n  File \"/tmp/ansible_VD77M_/ansible_module_na_ontap_net_ifgrp.py\", line 320, in main\n    obj.apply()\n  File \"/tmp/ansible_VD77M_/ansible_module_na_ontap_net_ifgrp.py\", line 276, in apply\n    ifgrp_ports_detail = self.get_if_grp_ports()\n  File \"/tmp/ansible_VD77M_/ansible_module_na_ontap_net_ifgrp.py\", line 185, in get_if_grp_ports\n    result = self.server.invoke_successfully(if_group_iter, True)\n  File \"/usr/local/lib/python2.7/dist-packages/netapp_lib/api/zapi/zapi.py\", line 294, in invoke_successfully\n    raise NaApiError(code, msg)\nnetapp_lib.api.zapi.zapi.NaApiError: NetApp API failed. Reason - 15661:entry doesn't exist\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c 'echo ~fgzx6022 &amp;&amp; sleep 0'
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908097.39-119102551277484 `" &amp;&amp; echo ansible-tmp-1531908097.39-119102551277484="` echo /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908097.39-119102551277484 `" ) &amp;&amp; sleep 0'
Using module file /home/fgzx6022/Work/python-env/ansible2.6/local/lib/python2.7/site-packages/ansible/modules/storage/netapp/na_ontap_net_ifgrp.py
<cloud-nas-y00n-prd.cloud.620nm.net> PUT /home/fgzx6022/.ansible/tmp/ansible-local-28921IRjFWh/tmpvmkBzP TO /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908097.39-119102551277484/na_ontap_net_ifgrp.py
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c 'chmod u+x /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908097.39-119102551277484/ /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908097.39-119102551277484/na_ontap_net_ifgrp.py &amp;&amp; sleep 0'
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c '/usr/bin/python /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908097.39-119102551277484/na_ontap_net_ifgrp.py &amp;&amp; sleep 0'
<cloud-nas-y00n-prd.cloud.620nm.net> EXEC /bin/sh -c 'rm -f -r /home/fgzx6022/.ansible/tmp/ansible-tmp-1531908097.39-119102551277484/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_5Y2eJR/ansible_module_na_ontap_net_ifgrp.py", line 324, in <module>
main()
File "/tmp/ansible_5Y2eJR/ansible_module_na_ontap_net_ifgrp.py", line 320, in main
obj.apply()
File "/tmp/ansible_5Y2eJR/ansible_module_na_ontap_net_ifgrp.py", line 276, in apply
ifgrp_ports_detail = self.get_if_grp_ports()
File "/tmp/ansible_5Y2eJR/ansible_module_na_ontap_net_ifgrp.py", line 185, in get_if_grp_ports
result = self.server.invoke_successfully(if_group_iter, True)
File "/usr/local/lib/python2.7/dist-packages/netapp_lib/api/zapi/zapi.py", line 294, in invoke_successfully
raise NaApiError(code, msg)
netapp_lib.api.zapi.zapi.NaApiError: NetApp API failed. Reason - 15661:entry doesn't exist

failed: [cloud-nas-y00n-prd.cloud.620nm.net] (item=[u'cloud-nas-y02n-prd', u'e0d']) => {
"changed": false,
"item": [
"cloud-nas-y02n-prd",
"e0d"
],
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_5Y2eJR/ansible_module_na_ontap_net_ifgrp.py\", line 324, in <module>\n    main()\n  File \"/tmp/ansible_5Y2eJR/ansible_module_na_ontap_net_ifgrp.py\", line 320, in main\n    obj.apply()\n  File \"/tmp/ansible_5Y2eJR/ansible_module_na_ontap_net_ifgrp.py\", line 276, in apply\n    ifgrp_ports_detail = self.get_if_grp_ports()\n  File \"/tmp/ansible_5Y2eJR/ansible_module_na_ontap_net_ifgrp.py\", line 185, in get_if_grp_ports\n    result = self.server.invoke_successfully(if_group_iter, True)\n  File \"/usr/local/lib/python2.7/dist-packages/netapp_lib/api/zapi/zapi.py\", line 294, in invoke_successfully\n    raise NaApiError(code, msg)\nnetapp_lib.api.zapi.zapi.NaApiError: NetApp API failed. Reason - 15661:entry doesn't exist\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}
to retry, use: --limit @/home/fgzx6022/Work/ansible-netapp/config.retry

PLAY RECAP *********************************************************************************************************************************
cloud-nas-y00n-prd.cloud.620nm.net : ok=1    changed=0    unreachable=0    failed=1

# Fixed code
def __init__(self):
    """
    Initialize the Ontap IfGrp class
    """
    self.argument_spec = netapp_utils.na_ontap_host_argument_spec()
    self.argument_spec.update(
        dict(
            state=dict(
                required=False, choices=["present", "absent"], default="present"
            ),
            distribution_function=dict(
                required=False, type="str", choices=["mac", "ip", "sequential", "port"]
            ),
            name=dict(required=True, type="str"),
            mode=dict(required=False, type="str"),
            node=dict(required=True, type="str"),
            ports=dict(required=False, type="list", aliases=["port"]),
        )
    )

    self.module = AnsibleModule(
        argument_spec=self.argument_spec,
        required_if=[("state", "present", ["distribution_function", "mode"])],
        supports_check_mode=True,
    )

    # set up variables
    self.na_helper = NetAppModule()
    self.parameters = self.na_helper.set_parameters(self.module.params)

    if HAS_NETAPP_LIB is False:
        self.module.fail_json(msg="the python NetApp-Lib module is required")
    else:
        self.server = netapp_utils.setup_na_ontap_zapi(module=self.module)
    return