title: VMware VM Portgroup change with Ansible 2.9.6
body: <p>My script doesn't change the portgroup of a VM Network adapter, what am I doing wrong ?</p>
  <p>Let's assume that I want to change the current portgroup named &quot;A&quot; to a different portgroup named &quot;B&quot;.</p>
  <pre><code>---
  - hosts: localhost
    gather_facts: no
    vars:
      vm_name: VM
    tasks:
    - name: Changing Portgroup for Network adapter 1
      vmware_guest_network:
        hostname: &quot;{{ vc_host }}&quot;
        username: &quot;{{ vc_user }}&quot;
        password: &quot;{{ vc_pass }}&quot;
        validate_certs: no
        name: &quot;{{ vm_name }}&quot;
        gather_network_info: false
        networks:
        - label: &quot;Network adapter 1&quot;
          name: &quot;B&quot;
          state: present
      delegate_to: localhost
      register: network_info 
  </code></pre>
  <p>I'm getting output that something changed, but in VM Settings nothing changed.</p>
  <pre><code>TASK [Changing Portgroup for Network Adapter 1] 
  ******************************************************************************
  changed: [localhost -&gt; localhost] 
  </code></pre>
  <p>I found that removing and adding a Network adapter changes the portgroup, but when I do that I cannot add a Network adapter type Flexible which I had in the first place.</p>
  <p>Edit1: After updating Ansible to 2.9.12 I get OK output when running the script, so it really isn't changing anything.</p>
  <pre><code>TASK [Changing Portgroup for Network Adapter 1] ******************************************************************************
  ok: [localhost]
  </code></pre>
  <p>Edit2: After a few days searching I found that it isn't possible to just change the portgroup with Ansible, so I used PowerCLI to help me with task.</p>
  <pre><code>---
  - hosts: localhost
    gather_facts: no
    vars:
      vm_name: &quot;VM&quot;
    tasks:
    - name: &quot;Changing the portgroup for {{ vm_name }}&quot;
      win_command: 'powershell.exe -ExecutionPolicy ByPass -File C:\Scripts\change_portgroup.ps1 {{ vm_name }}'
      delegate_to: WIN_SRV
  </code></pre>
  <p>With powershell script going like this:</p>
  <pre><code>$OldNetwork = &quot;PG old&quot;
  $NewNetwork = &quot;PG new&quot;
  
  Get-VM -Name $args[0] |Get-NetworkAdapter |Where {$_.NetworkName -eq $OldNetwork } |Set-NetworkAdapter -NetworkName $NewNetwork -Confirm:$false
  </code></pre>
  <p>Edit 3:
  I got it working with vmware community module. (Thanks @sky-jokerxx)</p>
  <p>First I installed it with command:</p>
  <pre><code>ansible-galaxy collection install community.vmware
  </code></pre>
  <p>Then used the module like this:</p>
  <pre><code>  - name: Change network
      community.vmware.vmware_guest_network:
        validate_certs: no
        hostname: '{{ vc_host }}'
        username: '{{ vc_user }}'
        password: '{{ vc_pass }}'
        name: '{{ vm_name }}'
        label: &quot;Network adapter 1&quot;
        network_name: &quot;B&quot;
        state: present
      delegate_to: localhost
  </code></pre>