Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure_rm_virtualmachine returns nboundLocalError: local variable 'boot_diag_storage_account' referenced before assignment even when boot_diagnostics enabled is set to no #159

Closed
Akasurde opened this issue Jun 14, 2020 · 4 comments · Fixed by #200

Comments

@Akasurde
Copy link
Member

From @mohankrishnavanga on Jun 14, 2020 07:55

SUMMARY

I am trying to use ansible for creating virtual machines and its components in azure and Im stuck with the actual VM creation with the error mentioned in the title. I do not want the boot_diagnostics so I wanted to disable it with "enabled: no" but it is throwing the error

ISSUE TYPE
  • Bug Report
COMPONENT NAME

azure_rm_virtualmachine

ANSIBLE VERSION
ansible 2.9.9
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/mk_user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.17 (default, Apr 15 2020, 17:20:14) [GCC 7.5.0]
CONFIGURATION

OS / ENVIRONMENT

Ubuntu 18.04-LTS (Azure VM)

STEPS TO REPRODUCE
main.yml
---

    - name: Create Network Interface
      azure_rm_networkinterface:
        name: "{{ nic_name }}"
        resource_group: "{{ rg_name }}"
        virtual_network: "{{ vnet_name }}"
        subnet_name: "{{ snet_name }}"
        security_group: "{{ nsg_name }}"
        location: "{{ location }}"
      register: nic_info
   
    - debug:
       var: nic_info.state.name
   
    - name: Create Managed disk for Data
      azure_rm_manageddisk:
         name: "{{ data_disk_name }}"
         location: "{{ location }}"
         resource_group: "{{ rg_name }}"
         disk_size_gb: 1000
         create_option: empty
         attach_caching: read_only
      register: data_disk
    
    - debug:
        var: data_disk
   
   
    - name: Create Azure VM
      azure_rm_virtualmachine:
       location: "{{ location }}"
       resource_group: "{{ rg_name }}"
       virtual_network: "{{ vnet_name }}"
       subnet: "{{ snet_name }}"
       name: "{{ vm_name }}"
       admin_username: "{{ vm_user }}"
       admin_password: "{{ vm_password }}"
       boot_diagnostics:
           enabled: no
       vm_size: "{{ vm_size }}"
       network_interfaces: "{{ nic_info.state.name }}"
       image:
         offer: "UbuntuServer"
         publisher: "Canonical"
         sku: "18.04-LTS"
         version: "latest"
       os_disk_name: "{{ os_disk_name }}"
       os_disk_caching: "ReadWrite"
       os_disk_size_gb: 30
       os_type: "Linux"
       managed_disk_type: "Premium_LRS"
       data_disks:
          - lun: 0
            managed_disk_id: "{{ data_disk.state.id }}"
      register: az_vm
   
    - debug:
       var: az_vm
EXPECTED RESULTS

Expected the VM to be created without any boot_diagnostics and errors.

ACTUAL RESULTS

Step for Create VM exits with error saying "UnboundLocalError: local variable 'boot_diag_storage_account' referenced before assignment"

TASK [setup-BuildVM : Create Azure VM] **********************************************************************************************************************
task path: /home/mk_user/ansible/roles/setup-BuildVM/tasks/main.yml:30
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: mk_user
<127.0.0.1> EXEC /bin/sh -c 'echo ~mk_user && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/mk_user/.ansible/tmp `"&& mkdir /home/mk_user/.ansible/tmp/ansible-tmp-1592121239.37-10263-106962153805147 && echo ansible-tmp-1592121239.37-10263-106962153805147="` echo /home/mk_user/.ansible/tmp/ansible-tmp-1592121239.37-10263-106962153805147 `" ) && sleep 0'
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/cloud/azure/azure_rm_virtualmachine.py
<127.0.0.1> PUT /home/mk_user/.ansible/tmp/ansible-local-10134bwlrCu/tmpI2nEix TO /home/mk_user/.ansible/tmp/ansible-tmp-1592121239.37-10263-106962153805147/AnsiballZ_azure_rm_virtualmachine.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/mk_user/.ansible/tmp/ansible-tmp-1592121239.37-10263-106962153805147/ /home/mk_user/.ansible/tmp/ansible-tmp-1592121239.37-10263-106962153805147/AnsiballZ_azure_rm_virtualmachine.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 /home/mk_user/.ansible/tmp/ansible-tmp-1592121239.37-10263-106962153805147/AnsiballZ_azure_rm_virtualmachine.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/mk_user/.ansible/tmp/ansible-tmp-1592121239.37-10263-106962153805147/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/home/mk_user/.ansible/tmp/ansible-tmp-1592121239.37-10263-106962153805147/AnsiballZ_azure_rm_virtualmachine.py", line 102, in <module>
    _ansiballz_main()
  File "/home/mk_user/.ansible/tmp/ansible-tmp-1592121239.37-10263-106962153805147/AnsiballZ_azure_rm_virtualmachine.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/mk_user/.ansible/tmp/ansible-tmp-1592121239.37-10263-106962153805147/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/python2.7/runpy.py", line 188, in run_module
    fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 82, in _run_module_code
    mod_name, mod_fname, mod_loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/tmp/ansible_azure_rm_virtualmachine_payload_urnW8j/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_urnW8j/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_urnW8j/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_urnW8j/ansible_azure_rm_virtualmachine_payload.zip/ansible/module_utils/azure_rm_common.py", line 348, in __init__
  File "/tmp/ansible_azure_rm_virtualmachine_payload_urnW8j/ansible_azure_rm_virtualmachine_payload.zip/ansible/modules/cloud/azure/azure_rm_virtualmachine.py", line 1347, in exec_module
UnboundLocalError: local variable 'boot_diag_storage_account' referenced before assignment
fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/mk_user/.ansible/tmp/ansible-tmp-1592121239.37-10263-106962153805147/AnsiballZ_azure_rm_virtualmachine.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/home/mk_user/.ansible/tmp/ansible-tmp-1592121239.37-10263-106962153805147/AnsiballZ_azure_rm_virtualmachine.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/mk_user/.ansible/tmp/ansible-tmp-1592121239.37-10263-106962153805147/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/python2.7/runpy.py\", line 188, in run_module\n    fname, loader, pkg_name)\n  File \"/usr/lib/python2.7/runpy.py\", line 82, in _run_module_code\n    mod_name, mod_fname, mod_loader, pkg_name)\n  File \"/usr/lib/python2.7/runpy.py\", line 72, in _run_code\n    exec code in run_globals\n  File \"/tmp/ansible_azure_rm_virtualmachine_payload_urnW8j/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_urnW8j/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_urnW8j/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_urnW8j/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_urnW8j/ansible_azure_rm_virtualmachine_payload.zip/ansible/modules/cloud/azure/azure_rm_virtualmachine.py\", line 1347, in exec_module\nUnboundLocalError: local variable 'boot_diag_storage_account' referenced before assignment\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Copied from original issue: ansible/ansible#70057

@mohankrishnavanga
Copy link

Hi, any leads on this please?

@davidt99
Copy link
Contributor

Remove the boot diagnostics option, there is no point to add enable: no.

@Fred-sun
Copy link
Collaborator

@Akasurde Thank you very much for submitting this problem. We will investigate. Until the problem is fixed, if you want to create boot_diagno=no, you can create the VM without specifying boot_, which defaults to False. Thank you very much!

@Fred-sun
Copy link
Collaborator

fixes by #200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants