Azure / Ansible

Ansible Solution Template on Azure
MIT License
7 stars 10 forks source link

azure_rm_virtualmachine fails if VM is turned off. #20

Open mrwalters1988 opened 4 years ago

mrwalters1988 commented 4 years ago

When I run this template either when a VM is powered on or does not exist, it runs fine. If the VM is deallocated an error occurs.

Role:

  azure_rm_virtualmachine:  
    resource_group: "{{ vm.resource_group | default(resourcegroup_name) }}"
    admin_username: "{{ admin_username }}"
    admin_password: "{{ admin_password }}"
    availability_set: "{{ vm.availability_set | default(omit) }}"
    name: "{{deployment + 'vm' + vm.name}}"
    short_hostname: "{{ vm.short_hostname | default(omit)}}"
    vm_size: "{{ vm.vm_size }}"
    os_type: "{{vm.os_type}}"
    os_disk_name: "{{ deployment + 'md' + vm.name + 'os'}}"
    os_disk_size_gb: "{{vm.os_disk_size_gb | default(128)}}"
    managed_disk_type: "{{vm.managed_disk_type | default('standard_lrs')}}"
    public_ip_allocation: "{{ 'Static' if (vm.include_public_ip is true) else 'Disabled' }}"
    network_interface_names: "{{(deployment + 'ni' + vm.name + 'nic')}}"
    subnet_name: "{{ vm.subnet_name }}"
    image: "{{ vmimage }}"
  register: vmout

host_vars:

vm: 
  - name: sftp
    os_type: Linux
    image: Ubuntu1604
    vm_size: Standard_D2_v3
    managed_disk_type: "Standard_LRS"
    include_public_ip: true
    subnet_name: DMZ

Result:

task path: /home/vagrant/deploy/roles/azure/virtualmachine/tasks/windows.yml:26
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: vagrant
<127.0.0.1> EXEC /bin/sh -c 'echo ~vagrant && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/vagrant/.ansible/tmp/ansible-tmp-1585812382.3722196-66903079952393 `" && echo ansible-tmp-1585812382.3722196-66903079952393="` echo /home/vagrant/.ansible/tmp/ansible-tmp-1585812382.3722196-66903079952393 `" ) && sleep 0'
Using module file /usr/local/lib/python3.6/dist-packages/ansible/modules/cloud/azure/azure_rm_virtualmachine.py
<127.0.0.1> PUT /home/vagrant/.ansible/tmp/ansible-local-14694xq2ibqlm/tmp_v7f9vy8 TO /home/vagrant/.ansible/tmp/ansible-tmp-1585812382.3722196-66903079952393/AnsiballZ_azure_rm_virtualmachine.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1585812382.3722196-66903079952393/ /home/vagrant/.ansible/tmp/ansible-tmp-1585812382.3722196-66903079952393/AnsiballZ_azure_rm_virtualmachine.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/vagrant/.ansible/tmp/ansible-tmp-1585812382.3722196-66903079952393/AnsiballZ_azure_rm_virtualmachine.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/vagrant/.ansible/tmp/ansible-tmp-1585812382.3722196-66903079952393/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1585812382.3722196-66903079952393/AnsiballZ_azure_rm_virtualmachine.py", line 102, in <module>
    _ansiballz_main()
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1585812382.3722196-66903079952393/AnsiballZ_azure_rm_virtualmachine.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1585812382.3722196-66903079952393/AnsiballZ_azure_rm_virtualmachine.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible.modules.cloud.azure.azure_rm_virtualmachine', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.6/runpy.py", line 205, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_azure_rm_virtualmachine_payload_2bjff7ma/ansible_azure_rm_virtualmachine_payload.zip/ansible/modules/cloud/azure/azure_rm_virtualmachine.py", line 2202, in <module>
  File "/tmp/ansible_azure_rm_virtualmachine_payload_2bjff7ma/ansible_azure_rm_virtualmachine_payload.zip/ansible/modules/cloud/azure/azure_rm_virtualmachine.py", line 2198, in main
  File "/tmp/ansible_azure_rm_virtualmachine_payload_2bjff7ma/ansible_azure_rm_virtualmachine_payload.zip/ansible/modules/cloud/azure/azure_rm_virtualmachine.py", line 901, in __init__
  File "/tmp/ansible_azure_rm_virtualmachine_payload_2bjff7ma/ansible_azure_rm_virtualmachine_payload.zip/ansible/module_utils/azure_rm_common.py", line 348, in __init__
  File "/tmp/ansible_azure_rm_virtualmachine_payload_2bjff7ma/ansible_azure_rm_virtualmachine_payload.zip/ansible/modules/cloud/azure/azure_rm_virtualmachine.py", line 1574, in exec_module
KeyError: 'diskSizeGB'
fatal: [azure]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1585812382.3722196-66903079952393/AnsiballZ_azure_rm_virtualmachine.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1585812382.3722196-66903079952393/AnsiballZ_azure_rm_virtualmachine.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1585812382.3722196-66903079952393/AnsiballZ_azure_rm_virtualmachine.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.cloud.azure.azure_rm_virtualmachine', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_azure_rm_virtualmachine_payload_2bjff7ma/ansible_azure_rm_virtualmachine_payload.zip/ansible/modules/cloud/azure/azure_rm_virtualmachine.py\", line 2202, in <module>\n  File \"/tmp/ansible_azure_rm_virtualmachine_payload_2bjff7ma/ansible_azure_rm_virtualmachine_payload.zip/ansible/modules/cloud/azure/azure_rm_virtualmachine.py\", line 2198, in main\n  File \"/tmp/ansible_azure_rm_virtualmachine_payload_2bjff7ma/ansible_azure_rm_virtualmachine_payload.zip/ansible/modules/cloud/azure/azure_rm_virtualmachine.py\", line 901, in __init__\n  File \"/tmp/ansible_azure_rm_virtualmachine_payload_2bjff7ma/ansible_azure_rm_virtualmachine_payload.zip/ansible/module_utils/azure_rm_common.py\", line 348, in __init__\n  File \"/tmp/ansible_azure_rm_virtualmachine_payload_2bjff7ma/ansible_azure_rm_virtualmachine_payload.zip/ansible/modules/cloud/azure/azure_rm_virtualmachine.py\", line 1574, in exec_module\nKeyError: 'diskSizeGB'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}