# Buggy code
def create_account(self):
    self.log("Creating account {0}".format(self.name))

    if not self.location:
        self.fail("Parameter error: location required when creating a storage account.")

    if not self.account_type:
        self.fail(
            "Parameter error: account_type required when creating a storage account."
        )

    self.check_name_availability()
    self.results["changed"] = True

    if self.check_mode:
        account_dict = dict(
            location=self.location,
            account_type=self.account_type,
            name=self.name,
            resource_group=self.resource_group,
            tags=dict(),
        )
        if self.tags:
            account_dict["tags"] = self.tags
        return account_dict
    sku = Sku(SkuName(self.account_type))
    sku.tier = SkuTier.standard if "Standard" in self.account_type else SkuTier.premium
    parameters = StorageAccountCreateParameters(
        sku, self.kind, self.location, tags=self.tags
    )
    self.log(str(parameters))
    try:
        poller = self.storage_client.storage_accounts.create(
            self.resource_group, self.name, parameters
        )
        self.get_poller_result(poller)
    except CloudError as e:
        self.log("Error creating storage account.")
        self.fail("Failed to create account: {0}".format(str(e)))
    # the poller doesn't actually return anything
    return self.get_account()


# 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 create_account(self):
    self.log("Creating account {0}".format(self.name))

    if not self.location:
        self.fail("Parameter error: location required when creating a storage account.")

    if not self.account_type:
        self.fail(
            "Parameter error: account_type required when creating a storage account."
        )

    if not self.access_tier and self.kind == "BlobStorage":
        self.fail(
            "Parameter error: access_tier required when creating a storage account of type BlobStorage."
        )

    self.check_name_availability()
    self.results["changed"] = True

    if self.check_mode:
        account_dict = dict(
            location=self.location,
            account_type=self.account_type,
            name=self.name,
            resource_group=self.resource_group,
            tags=dict(),
        )
        if self.tags:
            account_dict["tags"] = self.tags
        return account_dict
    sku = Sku(SkuName(self.account_type))
    sku.tier = SkuTier.standard if "Standard" in self.account_type else SkuTier.premium
    parameters = StorageAccountCreateParameters(
        sku, self.kind, self.location, tags=self.tags, access_tier=self.access_tier
    )
    self.log(str(parameters))
    try:
        poller = self.storage_client.storage_accounts.create(
            self.resource_group, self.name, parameters
        )
        self.get_poller_result(poller)
    except CloudError as e:
        self.log("Error creating storage account.")
        self.fail("Failed to create account: {0}".format(str(e)))
    # the poller doesn't actually return anything
    return self.get_account()