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

Key Error with ansible azure module azure_rm_networkinterface #387

Open
KarnG opened this issue Sep 30, 2020 · 0 comments
Open

Key Error with ansible azure module azure_rm_networkinterface #387

KarnG opened this issue Sep 30, 2020 · 0 comments

Comments

@KarnG
Copy link

KarnG commented Sep 30, 2020

There is a bug with ansible azure module azure_rm_networkinterface which gives Key Error for name parameter.

I am using ansible version: 2.9.0
Python Version: 3.6.9 and also tried(2.7.5)

Below is my playbook for creating VM in azure

$ cat new_vm_Creation.yml
---
- name: create azure vm
  hosts: localhost
  connection: local
  tasks:
   -  include_vars: azure_vars.yml

   - set_fact:
      host: "{{ azure_vm_name.split('.') }}"

   - set_fact:
       domain: "{{ host.1 }}.{{ host.2 }}"
   - debug:
       var: domain
   # using Python's capacities of Ansible, we can use the index() method of a list to target the element of all the
   # variables eg: azure_location being at the same position as domain in azure_domain.
   - set_fact:
        location: "{{ azure_location[azure_domain.index(domain)] }}"
   - debug:
       var: location

   - set_fact:
      res_group: "{{ azure_res_group[azure_domain.index(domain)] }}"
   - debug:
       var: res_group

   - set_fact:
      vnet: "{{ azure_vnet[azure_domain.index(domain)] }}"
   - debug:
       var: vnet

   - name: set azure env "{{ azure_account[azure_domain.index(domain)] }}"
     shell: "az account set -s {{ azure_account[azure_domain.index(domain)] }}"
   - debug:
       var: azure_account

   - name: create network security group that allows ssh
     azure_rm_securitygroup:
      resource_group: "{{ res_group }}"
      location: "{{ location }}"
      name: "{{ azure_vm_name }}-nsg"
      rules:
        - name: ssh
          protocol: Tcp
          destination_port_range: 22
          access: Allow
          priority: 100
          direction: Inbound

   - name: create virtual network interface card
     azure_rm_networkinterface:
      name: "{{ azure_vm_name }}-nic1"
      resource_group: "{{ res_group }}"
      location: "{{ location }}"
      subnet: "{{ azure_subnet_name }}"
      virtual_network: "{{ vnet }}"
      security_group: "{{ azure_vm_name }}-nsg"
      enable_accelerated_networking: true
      public_ip: no
      state: present

   - name: create vm
     azure_rm_virtualmachine:
      resource_group: "{{ res_group }}"
      location: "{{ location }}"
      name: "{{ azure_vm_name }}"
      vm_size: Standard_D4s_v3
      admin_username: xyz
      ssh_password_enabled: false
      ssh_public_keys:
        - path: /home/xyz/.ssh/authorized_keys
          key_data: "{{ public_key }}"
      network_interfaces: "{{ azure_vm_name }}-nic1"
      os_disk_name: "{{ azure_vm_name }}-osdisk"
      managed_disk_type: "{{ azure_os_disk_type }}"
      os_disk_caching: ReadWrite
      os_type: Linux
      image:
        id: "{{ azure_image_id }}"
        publisher: redhat
      plan:
        name: rhel-lvm78
        product: rhel-byos
        publisher: redhat

   - name: Add the managed disk to VM
     azure_rm_manageddisk:
       name: "{{ azure_vm_name }}-datadisk01"
       location: "{{ azure_location }}"
       resource_group: "{{ res_group }}"
       disk_size_gb: "{{ azure_disk_size }}"
       managed_by: "{{ azure_vm_name }}"
       storage_account_type: "{{ azure_data_disk_type }}"
       attach_caching: read_only

   - name: Ensure VM was created properly
     assert:
       that:
         - azure_vm.properties.provisioningState == 'Succeeded'
         - azure_vm.properties.availabilitySet.id

   - name: "wait for 3 Min"
     pause:
      minutes: 3

   - name: "Add post-install host to inventory"
     add_host:
       name: "{{ azure_vm_name }}"
       groups: postinstall_group

- name: "Start post install"
  hosts: postinstall_group
  gather_facts: True
  become: yes
  become_method: sudo
  become_user: root
  tasks:
    - name: "Post install"
      include_role:
        name: azure_license
...


Below is the Error details and this is only for azure_rm_networkinterface module.


TASK [create virtual network interface card] ****************************************************************************************************************
task path: /home/xyz/ansible_work/new_vm_Creation.yml:50
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: xyz
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible-tmp-1601448152.1657674-70974823509213 `" && echo ansible-tmp-1601448152.1657674-70974823509213="` echo /tmp/ansible-tmp-1601448152.1657674-70974823509213 `" ) && sleep 0'
Using module file /usr/local/lib/python3.6/dist-packages/ansible/modules/cloud/azure/azure_rm_networkinterface.py
<127.0.0.1> PUT /home/xyz/.ansible/tmp/ansible-local-2762h1jknjmk/tmpiupv02qc TO /tmp/ansible-tmp-1601448152.1657674-70974823509213/AnsiballZ_azure_rm_networkinterface.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /tmp/ansible-tmp-1601448152.1657674-70974823509213/ /tmp/ansible-tmp-1601448152.1657674-70974823509213/AnsiballZ_azure_rm_networkinterface.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /tmp/ansible-tmp-1601448152.1657674-70974823509213/AnsiballZ_azure_rm_networkinterface.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /tmp/ansible-tmp-1601448152.1657674-70974823509213/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible-tmp-1601448152.1657674-70974823509213/AnsiballZ_azure_rm_networkinterface.py", line 102, in <module>
    _ansiballz_main()
  File "/tmp/ansible-tmp-1601448152.1657674-70974823509213/AnsiballZ_azure_rm_networkinterface.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/tmp/ansible-tmp-1601448152.1657674-70974823509213/AnsiballZ_azure_rm_networkinterface.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible.modules.cloud.azure.azure_rm_networkinterface', init_globals=None, run_name='__main__', alter_sys=False)
  File "/usr/lib/python3.6/runpy.py", line 208, in run_module
    return _run_code(code, {}, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_azure_rm_networkinterface_payload_bifcddsl/ansible_azure_rm_networkinterface_payload.zip/ansible/modules/cloud/azure/azure_rm_networkinterface.py", line 877, in <module>
  File "/tmp/ansible_azure_rm_networkinterface_payload_bifcddsl/ansible_azure_rm_networkinterface_payload.zip/ansible/modules/cloud/azure/azure_rm_networkinterface.py", line 873, in main
  File "/tmp/ansible_azure_rm_networkinterface_payload_bifcddsl/ansible_azure_rm_networkinterface_payload.zip/ansible/modules/cloud/azure/azure_rm_networkinterface.py", line 595, in __init__
  File "/tmp/ansible_azure_rm_networkinterface_payload_bifcddsl/ansible_azure_rm_networkinterface_payload.zip/ansible/module_utils/azure_rm_common.py", line 348, in __init__
  File "/tmp/ansible_azure_rm_networkinterface_payload_bifcddsl/ansible_azure_rm_networkinterface_payload.zip/ansible/modules/cloud/azure/azure_rm_networkinterface.py", line 744, in exec_module
KeyError: 'name'

fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible-tmp-1601448152.1657674-70974823509213/AnsiballZ_azure_rm_networkinterface.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/tmp/ansible-tmp-1601448152.1657674-70974823509213/AnsiballZ_azure_rm_networkinterface.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/tmp/ansible-tmp-1601448152.1657674-70974823509213/AnsiballZ_azure_rm_networkinterface.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.cloud.azure.azure_rm_networkinterface', init_globals=None, run_name='__main__', alter_sys=False)\n  File \"/usr/lib/python3.6/runpy.py\", line 208, in run_module\n    return _run_code(code, {}, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_azure_rm_networkinterface_payload_bifcddsl/ansible_azure_rm_networkinterface_payload.zip/ansible/modules/cloud/azure/azure_rm_networkinterface.py\", line 877, in <module>\n  File \"/tmp/ansible_azure_rm_networkinterface_payload_bifcddsl/ansible_azure_rm_networkinterface_payload.zip/ansible/modules/cloud/azure/azure_rm_networkinterface.py\", line 873, in main\n  File \"/tmp/ansible_azure_rm_networkinterface_payload_bifcddsl/ansible_azure_rm_networkinterface_payload.zip/ansible/modules/cloud/azure/azure_rm_networkinterface.py\", line 595, in __init__\n  File \"/tmp/ansible_azure_rm_networkinterface_payload_bifcddsl/ansible_azure_rm_networkinterface_payload.zip/ansible/module_utils/azure_rm_common.py\", line 348, in __init__\n  File \"/tmp/ansible_azure_rm_networkinterface_payload_bifcddsl/ansible_azure_rm_networkinterface_payload.zip/ansible/modules/cloud/azure/azure_rm_networkinterface.py\", line 744, in exec_module\nKeyError: 'name'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}


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

No branches or pull requests

1 participant