# Buggy code
def __init__(self):
    self.module_arg_spec = dict(
        resource_group=dict(type="str", required=True),
        name=dict(type="str", required=True),
        state=dict(choices=["present", "absent"], default="present", type="str"),
        location=dict(type="str"),
        short_hostname=dict(type="str"),
        vm_size=dict(type="str", required=True),
        admin_username=dict(type="str"),
        admin_password=dict(type="str", no_log=True),
        ssh_password_enabled=dict(type="bool", default=True),
        ssh_public_keys=dict(type="list"),
        image=dict(type="dict"),
        storage_account_name=dict(type="str", aliases=["storage_account"]),
        storage_container_name=dict(
            type="str", aliases=["storage_container"], default="vhds"
        ),
        storage_blob_name=dict(type="str", aliases=["storage_blob"]),
        os_disk_caching=dict(
            type="str",
            aliases=["disk_caching"],
            choices=["ReadOnly", "ReadWrite"],
            default="ReadOnly",
        ),
        os_type=dict(type="str", choices=["Linux", "Windows"], default="Linux"),
        public_ip_allocation_method=dict(
            type="str",
            choices=["Dynamic", "Static"],
            default="Static",
            aliases=["public_ip_allocation"],
        ),
        open_ports=dict(type="list"),
        network_interface_names=dict(type="list", aliases=["network_interfaces"]),
        remove_on_absent=dict(type="list", default=["all"]),
        virtual_network_name=dict(type="str", aliases=["virtual_network"]),
        subnet_name=dict(type="str", aliases=["subnet"]),
        allocated=dict(type="bool", default=True),
        restarted=dict(type="bool", default=False),
        started=dict(type="bool", default=True),
    )

    self.resource_group = None
    self.name = None
    self.state = None
    self.location = None
    self.short_hostname = None
    self.vm_size = None
    self.admin_username = None
    self.admin_password = None
    self.ssh_password_enabled = None
    self.ssh_public_keys = None
    self.image = None
    self.storage_account_name = None
    self.storage_container_name = None
    self.storage_blob_name = None
    self.os_type = None
    self.os_disk_caching = None
    self.network_interface_names = None
    self.remove_on_absent = set()
    self.tags = None
    self.force = None
    self.public_ip_allocation_method = None
    self.open_ports = None
    self.virtual_network_name = None
    self.subnet_name = None
    self.allocated = None
    self.restarted = None
    self.started = None
    self.differences = None

    self.results = dict(
        changed=False,
        actions=[],
        powerstate_change=None,
        ansible_facts=dict(azure_vm=None),
    )

    super(AzureRMVirtualMachine, self).__init__(
        derived_arg_spec=self.module_arg_spec, supports_check_mode=True
    )


# Traceback (msrestazure.azure_exceptions.CloudError)
TASK [azure-vm-provision : Launch VM in Azure] *********************************
task path: /home/ec2-user/Ansible/roles/azure-vm-provision/tasks/windows.yml:5
Using module file /usr/local/lib/python2.7/site-packages/ansible/modules/core/cloud/azure/azure_rm_virtualmachine.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: ec2-user
<127.0.0.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1495723850.66-57642620789826 `" &amp;&amp; echo ansible-tmp-1495723850.66-57642620789826="` echo $HOME/.ansible/tmp/ansible-tmp-1495723850.66-57642620789826 `" ) &amp;&amp; sleep 0'
<127.0.0.1> PUT /tmp/tmpTQzyAQ TO /home/ec2-user/.ansible/tmp/ansible-tmp-1495723850.66-57642620789826/azure_rm_virtualmachine.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/ec2-user/.ansible/tmp/ansible-tmp-1495723850.66-57642620789826/ /home/ec2-user/.ansible/tmp/ansible-tmp-1495723850.66-57642620789826/azure_rm_virtualmachine.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2.7 /home/ec2-user/.ansible/tmp/ansible-tmp-1495723850.66-57642620789826/azure_rm_virtualmachine.py; rm -rf "/home/ec2-user/.ansible/tmp/ansible-tmp-1495723850.66-57642620789826/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_l_NvK6/ansible_module_azure_rm_virtualmachine.py", line 1305, in <module>
main()
File "/tmp/ansible_l_NvK6/ansible_module_azure_rm_virtualmachine.py", line 1302, in main
AzureRMVirtualMachine()
File "/tmp/ansible_l_NvK6/ansible_module_azure_rm_virtualmachine.py", line 548, in __init__
supports_check_mode=True)
File "/tmp/ansible_l_NvK6/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py", line 184, in __init__
File "/tmp/ansible_l_NvK6/ansible_module_azure_rm_virtualmachine.py", line 716, in exec_module
default_nic = self.create_default_nic()
File "/tmp/ansible_l_NvK6/ansible_module_azure_rm_virtualmachine.py", line 1256, in create_default_nic
for subnet in subnets:
File "/usr/lib/python2.7/dist-packages/msrest/paging.py", line 109, in __next__
self.advance_page()
File "/usr/lib/python2.7/dist-packages/msrest/paging.py", line 95, in advance_page
self._response = self._get_next(self.next_link)
File "/usr/lib/python2.7/dist-packages/azure/mgmt/network/operations/subnets_operations.py", line 350, in internal_paging
raise exp
msrestazure.azure_exceptions.CloudError: Azure Error: ResourceNotFound
Message: The Resource 'Microsoft.Network/virtualNetworks/subscriptions' under resource group '[azure_resource_group]' was not found.

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_name": "azure_rm_virtualmachine"
},
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_l_NvK6/ansible_module_azure_rm_virtualmachine.py\", line 1305, in <module>\n    main()\n  File \"/tmp/ansible_l_NvK6/ansible_module_azure_rm_virtualmachine.py\", line 1302, in main\n    AzureRMVirtualMachine()\n  File \"/tmp/ansible_l_NvK6/ansible_module_azure_rm_virtualmachine.py\", line 548, in __init__\n    supports_check_mode=True)\n  File \"/tmp/ansible_l_NvK6/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 184, in __init__\n  File \"/tmp/ansible_l_NvK6/ansible_module_azure_rm_virtualmachine.py\", line 716, in exec_module\n    default_nic = self.create_default_nic()\n  File \"/tmp/ansible_l_NvK6/ansible_module_azure_rm_virtualmachine.py\", line 1256, in create_default_nic\n    for subnet in subnets:\n  File \"/usr/lib/python2.7/dist-packages/msrest/paging.py\", line 109, in __next__\n    self.advance_page()\n  File \"/usr/lib/python2.7/dist-packages/msrest/paging.py\", line 95, in advance_page\n    self._response = self._get_next(self.next_link)\n  File \"/usr/lib/python2.7/dist-packages/azure/mgmt/network/operations/subnets_operations.py\", line 350, in internal_paging\n    raise exp\nmsrestazure.azure_exceptions.CloudError: Azure Error: ResourceNotFound\nMessage: The Resource 'Microsoft.Network/virtualNetworks/subscriptions' under resource group '[azure_resource_group]' was not found.\n",
"module_stdout": "",
"msg": "MODULE FAILURE"

# Fixed code
def __init__(self):
    self.module_arg_spec = dict(
        resource_group=dict(type="str", required=True),
        name=dict(type="str", required=True),
        state=dict(choices=["present", "absent"], default="present", type="str"),
        location=dict(type="str"),
        short_hostname=dict(type="str"),
        vm_size=dict(type="str", required=True),
        admin_username=dict(type="str"),
        admin_password=dict(type="str", no_log=True),
        ssh_password_enabled=dict(type="bool", default=True),
        ssh_public_keys=dict(type="list"),
        image=dict(type="dict"),
        storage_account_name=dict(type="str", aliases=["storage_account"]),
        storage_container_name=dict(
            type="str", aliases=["storage_container"], default="vhds"
        ),
        storage_blob_name=dict(type="str", aliases=["storage_blob"]),
        os_disk_caching=dict(
            type="str",
            aliases=["disk_caching"],
            choices=["ReadOnly", "ReadWrite"],
            default="ReadOnly",
        ),
        os_type=dict(type="str", choices=["Linux", "Windows"], default="Linux"),
        public_ip_allocation_method=dict(
            type="str",
            choices=["Dynamic", "Static"],
            default="Static",
            aliases=["public_ip_allocation"],
        ),
        open_ports=dict(type="list"),
        network_interface_names=dict(type="list", aliases=["network_interfaces"]),
        remove_on_absent=dict(type="list", default=["all"]),
        virtual_network_resource_group=dict(type="str"),
        virtual_network_name=dict(type="str", aliases=["virtual_network"]),
        subnet_name=dict(type="str", aliases=["subnet"]),
        allocated=dict(type="bool", default=True),
        restarted=dict(type="bool", default=False),
        started=dict(type="bool", default=True),
    )

    self.resource_group = None
    self.name = None
    self.state = None
    self.location = None
    self.short_hostname = None
    self.vm_size = None
    self.admin_username = None
    self.admin_password = None
    self.ssh_password_enabled = None
    self.ssh_public_keys = None
    self.image = None
    self.storage_account_name = None
    self.storage_container_name = None
    self.storage_blob_name = None
    self.os_type = None
    self.os_disk_caching = None
    self.network_interface_names = None
    self.remove_on_absent = set()
    self.tags = None
    self.force = None
    self.public_ip_allocation_method = None
    self.open_ports = None
    self.virtual_network_resource_group = None
    self.virtual_network_name = None
    self.subnet_name = None
    self.allocated = None
    self.restarted = None
    self.started = None
    self.differences = None

    self.results = dict(
        changed=False,
        actions=[],
        powerstate_change=None,
        ansible_facts=dict(azure_vm=None),
    )

    super(AzureRMVirtualMachine, self).__init__(
        derived_arg_spec=self.module_arg_spec, supports_check_mode=True
    )