# Buggy code
def account_obj_to_dict(self, account_obj):
    account_dict = dict(
        id=account_obj.id,
        name=account_obj.name,
        location=account_obj.location,
        resource_group=self.resource_group,
        type=account_obj.type,
        sku_tier=account_obj.sku.tier.value,
        sku_name=account_obj.sku.name.value,
        provisioning_state=account_obj.provisioning_state.value,
        secondary_location=account_obj.secondary_location,
        status_of_primary=(
            account_obj.status_of_primary.value
            if account_obj.status_of_primary is not None
            else None
        ),
        status_of_secondary=(
            account_obj.status_of_secondary.value
            if account_obj.status_of_secondary is not None
            else None
        ),
        primary_location=account_obj.primary_location,
    )
    account_dict["custom_domain"] = None
    if account_obj.custom_domain:
        account_dict["custom_domain"] = dict(
            name=account_obj.custom_domain.name,
            use_sub_domain=account_obj.custom_domain.use_sub_domain,
        )

    account_dict["primary_endpoints"] = None
    if account_obj.primary_endpoints:
        account_dict["primary_endpoints"] = dict(
            blob=account_obj.primary_endpoints.blob,
            queue=account_obj.primary_endpoints.queue,
            table=account_obj.primary_endpoints.table,
        )
    account_dict["secondary_endpoints"] = None
    if account_obj.secondary_endpoints:
        account_dict["secondary_endpoints"] = dict(
            blob=account_obj.secondary_endpoints.blob,
            queue=account_obj.secondary_endpoints.queue,
            table=account_obj.secondary_endpoints.table,
        )
    account_dict["tags"] = None
    if account_obj.tags:
        account_dict["tags"] = account_obj.tags
    return account_dict


# Traceback (msrestazure.azure_exceptions.CloudError)
ansible-playbook 2.4.0
config file = /ansible/ansible.cfg
configured module search path = [u'/Users/####/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible
executable location = /usr/local/bin/ansible-playbook
python version = 2.7.13 (default, Apr 23 2017, 16:50:35) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
Using /ansible/ansible.cfg as config file
setting up inventory plugins
Parsed /ansible/inventory/aq3.sh inventory source with script plugin
Set default localhost to localhost
Parsed /ansible/inventory/localhost.hosts inventory source with ini plugin
Parsed /ansible/inventory/optional.sh inventory source with script plugin
[WARNING]: Found both group and host with same name: localhost

Loading callback plugin default of type stdout, v2.0 from /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc
Loading callback plugin unnamed of type old, v1.0 from /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc
___________________________
< PLAYBOOK: copy_images.yml >
---------------------------
\   ^__^
\  (oo)\_______
(__)\       )\/\
||----w |
||     ||

1 plays in copy_images.yml
__________________
< PLAY [localhost] >
------------------
\   ^__^
\  (oo)\_______
(__)\       )\/\
||----w |
||     ||

2017-06-20T22:18:21.655381 (delta: 0.05648)         elapsed: 0.05648 **********
===============================================================================
META: ran handlers
____________________________________________________________
< TASK [Create resource group] >
------------------------------------------------------------
\   ^__^
\  (oo)\_______
(__)\       )\/\
||----w |
||     ||

task path: /ansible/copy_images.yml:21
2017-06-20T22:18:21.713703 (delta: 0.058203)         elapsed: 0.114802 ********
Using module_utils file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/module_utils/basic.py
Using module_utils file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/module_utils/azure_rm_common.py
Using module_utils file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/module_utils/_text.py
Using module_utils file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/module_utils/pycompat24.py
Using module_utils file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/module_utils/six/__init__.py
Using module_utils file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/module_utils/six/_six.py
Using module file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/modules/cloud/azure/azure_rm_resourcegroup.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: ####
<localhost> EXEC /bin/sh -c '/opt/local/bin/python &amp;&amp; sleep 0'
ok: [localhost] => {
"changed": false,
"contains_resources": true,
"failed": false,
"invocation": {
"module_args": {
"ad_user": null,
"append_tags": true,
"client_id": null,
"force": false,
"location": "southcentralus",
"name": "mygroup",
"password": null,
"profile": null,
"secret": null,
"state": "present",
"subscription_id": null,
"tags": null,
"tenant": null
}
},
"state": {
"id": "/subscriptions/###########################/resourceGroups/mygroup",
"location": "southcentralus",
"name": "mygroup",
"provisioning_state": "Succeeded",
"tags": {}
}
}
_________________________________________________
< TASK [Create standard lrs blob storage account] >
-------------------------------------------------
\   ^__^
\  (oo)\_______
(__)\       )\/\
||----w |
||     ||

task path: /ansible/copy_images.yml:30
2017-06-20T22:18:23.173263 (delta: 0.050252)         elapsed: 1.574362 ********
Using module_utils file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/module_utils/basic.py
Using module_utils file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/module_utils/azure_rm_common.py
Using module_utils file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/module_utils/_text.py
Using module_utils file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/module_utils/pycompat24.py
Using module_utils file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/module_utils/six/__init__.py
Using module_utils file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/module_utils/six/_six.py
Using module file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/modules/cloud/azure/azure_rm_storageaccount.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: ####
<localhost> EXEC /bin/sh -c '/opt/local/bin/python &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/var/folders/mh/twpnm4s11q1d2mp23yx137t00000gp/T/ansible_vKyn6G/ansible_module_azure_rm_storageaccount.py", line 447, in <module>
main()
File "/var/folders/mh/twpnm4s11q1d2mp23yx137t00000gp/T/ansible_vKyn6G/ansible_module_azure_rm_storageaccount.py", line 444, in main
AzureRMStorageAccount()
File "/var/folders/mh/twpnm4s11q1d2mp23yx137t00000gp/T/ansible_vKyn6G/ansible_module_azure_rm_storageaccount.py", line 205, in __init__
supports_check_mode=True)
File "/var/folders/mh/twpnm4s11q1d2mp23yx137t00000gp/T/ansible_vKyn6G/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py", line 197, in __init__
File "/var/folders/mh/twpnm4s11q1d2mp23yx137t00000gp/T/ansible_vKyn6G/ansible_module_azure_rm_storageaccount.py", line 241, in exec_module
self.results['state'] = self.create_account()
File "/var/folders/mh/twpnm4s11q1d2mp23yx137t00000gp/T/ansible_vKyn6G/ansible_module_azure_rm_storageaccount.py", line 402, in create_account
self.get_poller_result(poller)
File "/var/folders/mh/twpnm4s11q1d2mp23yx137t00000gp/T/ansible_vKyn6G/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py", line 411, in get_poller_result
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/msrestazure/azure_operation.py", line 486, in wait
raise self._exception
msrestazure.azure_exceptions.CloudError: Azure Error: InvalidAccessTier
Message: The storage account property 'accessTier' is invalid or cannot be set at this time.

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/mh/twpnm4s11q1d2mp23yx137t00000gp/T/ansible_vKyn6G/ansible_module_azure_rm_storageaccount.py\", line 447, in <module>\n    main()\n  File \"/var/folders/mh/twpnm4s11q1d2mp23yx137t00000gp/T/ansible_vKyn6G/ansible_module_azure_rm_storageaccount.py\", line 444, in main\n    AzureRMStorageAccount()\n  File \"/var/folders/mh/twpnm4s11q1d2mp23yx137t00000gp/T/ansible_vKyn6G/ansible_module_azure_rm_storageaccount.py\", line 205, in __init__\n    supports_check_mode=True)\n  File \"/var/folders/mh/twpnm4s11q1d2mp23yx137t00000gp/T/ansible_vKyn6G/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 197, in __init__\n  File \"/var/folders/mh/twpnm4s11q1d2mp23yx137t00000gp/T/ansible_vKyn6G/ansible_module_azure_rm_storageaccount.py\", line 241, in exec_module\n    self.results['state'] = self.create_account()\n  File \"/var/folders/mh/twpnm4s11q1d2mp23yx137t00000gp/T/ansible_vKyn6G/ansible_module_azure_rm_storageaccount.py\", line 402, in create_account\n    self.get_poller_result(poller)\n  File \"/var/folders/mh/twpnm4s11q1d2mp23yx137t00000gp/T/ansible_vKyn6G/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 411, in get_poller_result\n  File \"/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/msrestazure/azure_operation.py\", line 486, in wait\n    raise self._exception\nmsrestazure.azure_exceptions.CloudError: Azure Error: InvalidAccessTier\nMessage: The storage account property 'accessTier' is invalid or cannot be set at this time.\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}
to retry, use: --limit @/ansible/copy_images.retry
____________
< PLAY RECAP >
------------
\   ^__^
\  (oo)\_______
(__)\       )\/\
||----w |
||     ||

localhost                  : ok=2    changed=0    unreachable=0    failed=1

2017-06-20T22:18:29.641144 (delta: 6.467837)         elapsed: 8.042243 ********
===============================================================================

# Fixed code
def account_obj_to_dict(self, account_obj):
    account_dict = dict(
        id=account_obj.id,
        name=account_obj.name,
        location=account_obj.location,
        resource_group=self.resource_group,
        type=account_obj.type,
        access_tier=(
            account_obj.access_tier.value
            if account_obj.access_tier is not None
            else None
        ),
        sku_tier=account_obj.sku.tier.value,
        sku_name=account_obj.sku.name.value,
        provisioning_state=account_obj.provisioning_state.value,
        secondary_location=account_obj.secondary_location,
        status_of_primary=(
            account_obj.status_of_primary.value
            if account_obj.status_of_primary is not None
            else None
        ),
        status_of_secondary=(
            account_obj.status_of_secondary.value
            if account_obj.status_of_secondary is not None
            else None
        ),
        primary_location=account_obj.primary_location,
    )
    account_dict["custom_domain"] = None
    if account_obj.custom_domain:
        account_dict["custom_domain"] = dict(
            name=account_obj.custom_domain.name,
            use_sub_domain=account_obj.custom_domain.use_sub_domain,
        )

    account_dict["primary_endpoints"] = None
    if account_obj.primary_endpoints:
        account_dict["primary_endpoints"] = dict(
            blob=account_obj.primary_endpoints.blob,
            queue=account_obj.primary_endpoints.queue,
            table=account_obj.primary_endpoints.table,
        )
    account_dict["secondary_endpoints"] = None
    if account_obj.secondary_endpoints:
        account_dict["secondary_endpoints"] = dict(
            blob=account_obj.secondary_endpoints.blob,
            queue=account_obj.secondary_endpoints.queue,
            table=account_obj.secondary_endpoints.table,
        )
    account_dict["tags"] = None
    if account_obj.tags:
        account_dict["tags"] = account_obj.tags
    return account_dict