community.vmware icon indicating copy to clipboard operation
community.vmware copied to clipboard

Guest Module does not work on VMWare Cloud on AWS (VMC) after change from NVDS to VDS

Open skain80 opened this issue 3 years ago • 6 comments

SUMMARY

Module does not work on VMWare Cloud on AWS after change from NVDS to VDS

"msg": "Failed to find distributed virtual switch which is associated with distributed virtual portgroup 'NONPROD'. Make sure hostsystem is associated with the given distributed virtual portgroup. Also, check if user has correct permission to access distributed virtual switch in the given portgroup."

My guess is this change: https://kb.vmware.com/s/article/82487

ISSUE TYPE
  • Bug Report
COMPONENT NAME

https://github.com/ansible-collections/community.vmware/blob/main/plugins/modules/vmware_guest.py#L1872

ANSIBLE VERSION
2 skain@archibald ~/git/ansible % ansible --version
ansible [core 2.13.1]
  config file = /home/skain/git/ansible/ansible.cfg
  configured module search path = ['/home/skain/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/skain/git/ansible/venv/lib/python3.10/site-packages/ansible
  ansible collection location = /home/skain/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/skain/git/ansible/venv/bin/ansible
  python version = 3.10.5 (main, Jun  6 2022, 18:49:26) [GCC 12.1.0]
  jinja version = 3.1.2
  libyaml = True
skain@archibald ~/git/ansible % 
COLLECTION VERSION
skain@archibald ~/git/ansible % ansible-galaxy collection list community.general

# /home/skain/git/ansible/venv/lib/python3.10/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 5.0.2  
skain@archibald ~/git/ansible % ansible-galaxy collection list community.vmware 

# /home/skain/git/ansible/venv/lib/python3.10/site-packages/ansible_collections
Collection       Version
---------------- -------
community.vmware 2.6.0  
CONFIGURATION

OS / ENVIRONMENT

Target SDDC Version: 1.16v5

(it still works with SDDC Version: 1.16v4)

STEPS TO REPRODUCE
---
- name: make vmc vm
  hosts: localhost
  connection: local
  gather_facts: no
  become: no
  
  tasks:
  - name: vm in SDDC
    community.vmware.vmware_guest:
      datacenter: SDDC-Datacenter
      cluster: Cluster-1
      #esxi_hostname: 10.144.130.5
      hostname: x.x.x.x
      username: x.x.x.x
      password: xxxxxx
      folder: /SDDC-Datacenter/vm/Workloads
      name: test_vm_0001
      state: "{{ state }}"
      #resource_pool: Compute-ResourcePool
      validate_certs: false
      guest_id: centos64Guest
      #template: centos7-template-2022-02-24
      disk:
      - size_gb: 10
        type: thin
        datastore: WorkloadDatastore
      hardware:
        memory_mb: 512
        num_cpus: 4
      networks:
      - name: NONPROD
        ip: x.x.x.x
        netmask: 255.255.255.0
      wait_for_ip_address: false
    delegate_to: localhost
    register: deploy_vm
    changed_when: false
    tags:
    - euw3
EXPECTED RESULTS
skain@archibald ~/git/ansible % ansible-playbook -l localhost vmprov.yaml -e "state=poweredoff" --tags euc1      
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [make vmc vm] ***********************************************************************************************************************************************************************************************

TASK [vm in EUC1] ************************************************************************************************************************************************************************************************
ok: [localhost]

PLAY RECAP *******************************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
ACTUAL RESULTS
skain@archibald ~/git/ansible % ansible-playbook -l localhost vmprov.yaml -e "state=poweredoff" --tags euw3
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [make vmc vm] ***********************************************************************************************************************************************************************************************

TASK [vm in EUW3] ************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to find distributed virtual switch which is associated with distributed virtual portgroup 'NONPROD'. Make sure hostsystem is associated with the given distributed virtual portgroup. Also, check if user has correct permission to access distributed virtual switch in the given portgroup."}

PLAY RECAP *******************************************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

skain80 avatar Jul 07 '22 15:07 skain80

Files identified in the description: None

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot avatar Jul 07 '22 15:07 ansibullbot

I got something working by adding a new elif block which includes the new property net_obj.config.logicalSwitchUuid

            if hasattr(net_obj, 'portKeys') and not net_obj.config.logicalSwitchUuid:
            ...
            ...
            elif net_obj.config.logicalSwitchUuid and not isinstance(net_obj, vim.OpaqueNetwork):
                # VMC 1.16v5
                # https://kb.vmware.com/s/article/82487
                nic.device.backing = vim.vm.device.VirtualEthernetCard.OpaqueNetworkBackingInfo()
                network_id = net_obj.config.logicalSwitchUuid
                nic.device.backing.opaqueNetworkType = 'nsx.LogicalSwitch'
                nic.device.backing.opaqueNetworkId = network_id
                nic.device.deviceInfo.summary = 'nsx.LogicalSwitch: %s' % network_id
                nic_change_detected = True
                

skain80 avatar Jul 07 '22 22:07 skain80

@skain80 Would you be interested in opening a PR with your findings? Thanks

Akasurde avatar Jul 08 '22 10:07 Akasurde

I will do a bit more testing, then will open a PR @Akasurde

skain80 avatar Jul 08 '22 12:07 skain80

I am also seeing this issue.

csarraz avatar Jul 13 '22 14:07 csarraz

Seeing this exact issue on Dell VMC. Would love a PR or work around!

gruidl avatar Jul 13 '22 15:07 gruidl