# Buggy code
def gethash(self):
    if not getattr(self, "_cachedhash", None):
        spec = inspect.getargspec(self.__init__)
        valuetuple = tuple([getattr(self, x, None) for x in spec.args if x != "self"])
        self._cachedhash = hash(valuetuple)
    return self._cachedhash


# Traceback (msrest.exceptions.SerializationError)
(venv) [tony@localhost ansible_2.5-rc3]$ ansible-playbook azure_rm_dnsrecordset.yml -vvvv
ansible-playbook 2.5.0rc3 (stable-2.5 144e5ae65a) last updated 2018/03/18 20:38:45 (GMT +100)
config file = None
configured module search path = [u'/home/tony/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /home/tony/devel/ansible_2.5-rc3/lib/ansible
executable location = ./bin/ansible-playbook
python version = 2.7.14 (default, Dec  9 2017, 20:52:12) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
No config file found; using defaults
setting up inventory plugins
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

Loading callback plugin default of type stdout, v2.0 from /home/tony/devel/ansible_2.5-rc3/lib/ansible/plugins/callback/default.pyc

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

PLAY [demonstrate azure_rm_dnsrecordset TXT record issue] ********************************************************************************************************
META: ran handlers

TASK [create resource group] *************************************************************************************************************************************
task path: /home/tony/devel/ansible_2.5-rc3/azure_rm_dnsrecordset.yml:15
Using module file /home/tony/devel/ansible_2.5-rc3/lib/ansible/modules/cloud/azure/azure_rm_resourcegroup.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: tony
<127.0.0.1> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/tony/.ansible/tmp/ansible-tmp-1521408427.44-127941676971799 `" &amp;&amp; echo ansible-tmp-1521408427.44-127941676971799="` echo /home/tony/.ansible/tmp/ansible-tmp-1521408427.44-127941676971799 `" ) &amp;&amp; sleep 0'
<127.0.0.1> PUT /home/tony/.ansible/tmp/ansible-local-17458sfU_dJ/tmpHcSrjk TO /home/tony/.ansible/tmp/ansible-tmp-1521408427.44-127941676971799/azure_rm_resourcegroup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/tony/.ansible/tmp/ansible-tmp-1521408427.44-127941676971799/ /home/tony/.ansible/tmp/ansible-tmp-1521408427.44-127941676971799/azure_rm_resourcegroup.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/home/tony/devel/ansible_2.5-rc3/venv/bin/python /home/tony/.ansible/tmp/ansible-tmp-1521408427.44-127941676971799/azure_rm_resourcegroup.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/tony/.ansible/tmp/ansible-tmp-1521408427.44-127941676971799/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
changed: [localhost] => {
"changed": true,
"contains_resources": false,
"invocation": {
"module_args": {
"ad_user": null,
"api_profile": "latest",
"append_tags": true,
"auth_source": null,
"cert_validation_mode": null,
"client_id": null,
"cloud_environment": null,
"force": false,
"location": "ukwest",
"name": "Testing",
"password": null,
"profile": null,
"secret": null,
"state": "present",
"subscription_id": null,
"tags": null,
"tenant": null
}
},
"state": {
"id": "/subscriptions/c87516cf-4782-45a0-8597-fb290288f2e7/resourceGroups/Testing",
"location": "ukwest",
"name": "Testing",
"provisioning_state": "Succeeded",
"tags": null
}
}

TASK [Create a DNS zone] *****************************************************************************************************************************************
task path: /home/tony/devel/ansible_2.5-rc3/azure_rm_dnsrecordset.yml:22
Using module file /home/tony/devel/ansible_2.5-rc3/lib/ansible/modules/cloud/azure/azure_rm_dnszone.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: tony
<127.0.0.1> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/tony/.ansible/tmp/ansible-tmp-1521408430.64-25732376220852 `" &amp;&amp; echo ansible-tmp-1521408430.64-25732376220852="` echo /home/tony/.ansible/tmp/ansible-tmp-1521408430.64-25732376220852 `" ) &amp;&amp; sleep 0'
<127.0.0.1> PUT /home/tony/.ansible/tmp/ansible-local-17458sfU_dJ/tmpcB038t TO /home/tony/.ansible/tmp/ansible-tmp-1521408430.64-25732376220852/azure_rm_dnszone.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/tony/.ansible/tmp/ansible-tmp-1521408430.64-25732376220852/ /home/tony/.ansible/tmp/ansible-tmp-1521408430.64-25732376220852/azure_rm_dnszone.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/home/tony/devel/ansible_2.5-rc3/venv/bin/python /home/tony/.ansible/tmp/ansible-tmp-1521408430.64-25732376220852/azure_rm_dnszone.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/tony/.ansible/tmp/ansible-tmp-1521408430.64-25732376220852/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
[WARNING]: Azure API profile latest does not define an entry for DnsManagementClient

changed: [localhost] => {
"changed": true,
"check_mode": false,
"invocation": {
"module_args": {
"ad_user": null,
"api_profile": "latest",
"append_tags": true,
"auth_source": null,
"cert_validation_mode": null,
"client_id": null,
"cloud_environment": null,
"name": "testing.uk",
"password": null,
"profile": null,
"resource_group": "Testing",
"secret": null,
"state": "present",
"subscription_id": null,
"tags": null,
"tenant": null
}
},
"state": {
"id": "/subscriptions/c87516cf-4782-45a0-8597-fb290288f2e7/resourceGroups/testing/providers/Microsoft.Network/dnszones/testing.uk",
"name": "testing.uk",
"name_servers": [
"ns1-07.azure-dns.com.",
"ns2-07.azure-dns.net.",
"ns3-07.azure-dns.org.",
"ns4-07.azure-dns.info."
],
"number_of_record_sets": 2,
"tags": {}
}
}

TASK [ensure an "A" record set with multiple records] ************************************************************************************************************
task path: /home/tony/devel/ansible_2.5-rc3/azure_rm_dnsrecordset.yml:28
Using module file /home/tony/devel/ansible_2.5-rc3/lib/ansible/modules/cloud/azure/azure_rm_dnsrecordset.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: tony
<127.0.0.1> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/tony/.ansible/tmp/ansible-tmp-1521408434.66-105106934414168 `" &amp;&amp; echo ansible-tmp-1521408434.66-105106934414168="` echo /home/tony/.ansible/tmp/ansible-tmp-1521408434.66-105106934414168 `" ) &amp;&amp; sleep 0'
<127.0.0.1> PUT /home/tony/.ansible/tmp/ansible-local-17458sfU_dJ/tmpgQXMRj TO /home/tony/.ansible/tmp/ansible-tmp-1521408434.66-105106934414168/azure_rm_dnsrecordset.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/tony/.ansible/tmp/ansible-tmp-1521408434.66-105106934414168/ /home/tony/.ansible/tmp/ansible-tmp-1521408434.66-105106934414168/azure_rm_dnsrecordset.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/home/tony/devel/ansible_2.5-rc3/venv/bin/python /home/tony/.ansible/tmp/ansible-tmp-1521408434.66-105106934414168/azure_rm_dnsrecordset.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/tony/.ansible/tmp/ansible-tmp-1521408434.66-105106934414168/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
changed: [localhost] => {
"changed": true,
"invocation": {
"module_args": {
"ad_user": null,
"api_profile": "latest",
"append_tags": true,
"auth_source": null,
"cert_validation_mode": null,
"client_id": null,
"cloud_environment": null,
"password": null,
"profile": null,
"record_mode": "purge",
"record_type": "A",
"records": [
{
"entry": "192.168.100.101",
"ipv4_address": "192.168.100.101"
},
{
"entry": "192.168.100.102",
"ipv4_address": "192.168.100.102"
},
{
"entry": "192.168.100.103",
"ipv4_address": "192.168.100.103"
}
],
"relative_name": "www",
"resource_group": "Testing",
"secret": null,
"state": "present",
"subscription_id": null,
"tags": null,
"tenant": null,
"time_to_live": 3600,
"zone_name": "testing.uk"
}
}
}

TASK [create TXT record in a new record set] *********************************************************************************************************************
task path: /home/tony/devel/ansible_2.5-rc3/azure_rm_dnsrecordset.yml:40
Using module file /home/tony/devel/ansible_2.5-rc3/lib/ansible/modules/cloud/azure/azure_rm_dnsrecordset.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: tony
<127.0.0.1> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/tony/.ansible/tmp/ansible-tmp-1521408438.89-195623484547904 `" &amp;&amp; echo ansible-tmp-1521408438.89-195623484547904="` echo /home/tony/.ansible/tmp/ansible-tmp-1521408438.89-195623484547904 `" ) &amp;&amp; sleep 0'
<127.0.0.1> PUT /home/tony/.ansible/tmp/ansible-local-17458sfU_dJ/tmpHaYgU6 TO /home/tony/.ansible/tmp/ansible-tmp-1521408438.89-195623484547904/azure_rm_dnsrecordset.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/tony/.ansible/tmp/ansible-tmp-1521408438.89-195623484547904/ /home/tony/.ansible/tmp/ansible-tmp-1521408438.89-195623484547904/azure_rm_dnsrecordset.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/home/tony/devel/ansible_2.5-rc3/venv/bin/python /home/tony/.ansible/tmp/ansible-tmp-1521408438.89-195623484547904/azure_rm_dnsrecordset.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/tony/.ansible/tmp/ansible-tmp-1521408438.89-195623484547904/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_sRX1FZ/ansible_module_azure_rm_dnsrecordset.py", line 387, in <module>
main()
File "/tmp/ansible_sRX1FZ/ansible_module_azure_rm_dnsrecordset.py", line 384, in main
AzureRMRecordSet()
File "/tmp/ansible_sRX1FZ/ansible_module_azure_rm_dnsrecordset.py", line 273, in __init__
super(AzureRMRecordSet, self).__init__(self.module_arg_spec, required_if=required_if, supports_check_mode=True)
File "/tmp/ansible_sRX1FZ/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py", line 345, in __init__
File "/tmp/ansible_sRX1FZ/ansible_module_azure_rm_dnsrecordset.py", line 338, in exec_module
rsout = self.dns_client.record_sets.create_or_update(self.resource_group, self.zone_name, self.relative_name, self.record_type, record_set)
File "/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/azure/mgmt/dns/operations/record_sets_operations.py", line 189, in create_or_update
body_content = self._serialize.body(parameters, 'RecordSet')
File "/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py", line 476, in body
return self._serialize(data, data_type, **kwargs)
File "/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py", line 399, in _serialize
target_obj, data_type, **kwargs)
File "/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py", line 611, in serialize_data
return self._serialize(data, **kwargs)
File "/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py", line 422, in _serialize
orig_attr, attr_type, **kwargs)
File "/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py", line 604, in serialize_data
data, data_type[1:-1], **kwargs)
File "/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py", line 660, in serialize_iter
self.serialize_data(d, iter_type, **kwargs))
File "/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py", line 611, in serialize_data
return self._serialize(data, **kwargs)
File "/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py", line 422, in _serialize
orig_attr, attr_type, **kwargs)
File "/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py", line 604, in serialize_data
data, data_type[1:-1], **kwargs)
File "/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py", line 655, in serialize_iter
raise SerializationError("Refuse str type as a valid iter type.")
msrest.exceptions.SerializationError: Refuse str type as a valid iter type.

fatal: [localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_sRX1FZ/ansible_module_azure_rm_dnsrecordset.py\", line 387, in <module>\n    main()\n  File \"/tmp/ansible_sRX1FZ/ansible_module_azure_rm_dnsrecordset.py\", line 384, in main\n    AzureRMRecordSet()\n  File \"/tmp/ansible_sRX1FZ/ansible_module_azure_rm_dnsrecordset.py\", line 273, in __init__\n    super(AzureRMRecordSet, self).__init__(self.module_arg_spec, required_if=required_if, supports_check_mode=True)\n  File \"/tmp/ansible_sRX1FZ/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 345, in __init__\n  File \"/tmp/ansible_sRX1FZ/ansible_module_azure_rm_dnsrecordset.py\", line 338, in exec_module\n    rsout = self.dns_client.record_sets.create_or_update(self.resource_group, self.zone_name, self.relative_name, self.record_type, record_set)\n  File \"/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/azure/mgmt/dns/operations/record_sets_operations.py\", line 189, in create_or_update\n    body_content = self._serialize.body(parameters, 'RecordSet')\n  File \"/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py\", line 476, in body\n    return self._serialize(data, data_type, **kwargs)\n  File \"/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py\", line 399, in _serialize\n    target_obj, data_type, **kwargs)\n  File \"/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py\", line 611, in serialize_data\n    return self._serialize(data, **kwargs)\n  File \"/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py\", line 422, in _serialize\n    orig_attr, attr_type, **kwargs)\n  File \"/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py\", line 604, in serialize_data\n    data, data_type[1:-1], **kwargs)\n  File \"/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py\", line 660, in serialize_iter\n    self.serialize_data(d, iter_type, **kwargs))\n  File \"/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py\", line 611, in serialize_data\n    return self._serialize(data, **kwargs)\n  File \"/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py\", line 422, in _serialize\n    orig_attr, attr_type, **kwargs)\n  File \"/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py\", line 604, in serialize_data\n    data, data_type[1:-1], **kwargs)\n  File \"/home/tony/devel/ansible_2.5-rc3/venv/lib/python2.7/site-packages/msrest/serialization.py\", line 655, in serialize_iter\n    raise SerializationError(\"Refuse str type as a valid iter type.\")\nmsrest.exceptions.SerializationError: Refuse str type as a valid iter type.\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}
to retry, use: --limit @/home/tony/devel/ansible_2.5-rc3/azure_rm_dnsrecordset.retry

PLAY RECAP *******************************************************************************************************************************************************
localhost                  : ok=3    changed=3    unreachable=0    failed=1

# Fixed code
def gethash(self):
    if not getattr(self, "_cachedhash", None):
        spec = inspect.getargspec(self.__init__)
        valuetuple = tuple(
            map(
                lambda v: v if not isinstance(v, list) else str(v),
                [getattr(self, x, None) for x in spec.args if x != "self"],
            )
        )
        self._cachedhash = hash(valuetuple)
    return self._cachedhash