0

Im using ansible 2.9.2, i need to replace network adapter on vmware specific vm.

In my vcenter vm settings i see :

Networks: Vlan_12

My playbook doesnt see that network name.

  tasks:
    - name:  Changing network adapter
      vmware_guest_network:
        datacenter: "{{ datacenter"}} 
        hostname: "{{ vcenter_server }}"
        username: "{{ vcenter_user  }}"
        password: "{{ vcenter_pass }}"
        folder: "{{ folder }}"
        cluster: "{{ cluster }}"
        validate_certs: no
        name: test
        networks:
          - name: "Vlan_12"
            vlan: "Vlan_12"
            connected: false
            state: absent
      register: output

I get this error: fatal: [localhost]: FAILED! => {"changed": false, "msg": "Network 'Vlan_12' does not exist."}

Im trying to replace vlan_12 with another network adapter named Vlan_13, so i tried first to delete the exsisting network adapter. in ansible docs they have a very limited examples. Thanks.

Batchen Regev
  • 685
  • 1
  • 7
  • 28

3 Answers3

1

You dont have to poweroff the machine while addin/removing networks. You can remove/add nic on the fly, well at least on linux vm's not sure about Win vm's.

pio zylka
  • 11
  • 2
  • This should rather be a comment on [that](https://stackoverflow.com/a/59627320/11942268) answer instead of an answer to the question. – stackprotector Apr 29 '20 at 09:35
1

Changing networks live works just fine. All you need is state: present, the label of your current interface (almost certainly 'Network adapter 1', which is the default for the first network interface), and the name of the port group that you'd like to connect to this interface.

Here's the playbook I've been using:

---
- hosts: localhost
  gather_facts: no
  tasks:
    - name: migrate network
      vmware_guest_network:
        hostname: '{{ vcenter_hostname }}'
        username: '{{ vcenter_username }}'
        password: '{{ vcenter_password }}'
        datacenter: '{{ datacenter }}'
        validate_certs: False
        name: '{{ vm_hostname }}'
        gather_network_info: False
        networks:
          - state: present
            label: "Network adapter 1"
            name: '{{ new_net_name }}'
      delegate_to: localhost
Mark
  • 11
  • 1
0

You need vmware specific machine to be powerdoff so you can change network adapter:

  tasks:
    - name:  Changing network adapter
      vmware_guest_network:
        datacenter: "{{ datacenter"}} 
        hostname: "{{ vcenter_server }}"
        username: "{{ vcenter_user  }}"
        password: "{{ vcenter_pass }}"
        folder: "{{ folder }}"
        cluster: "{{ cluster }}"
        validate_certs: no
        name: test
        networks:
        - name: "Vlan_12"
          label: "Network adapter 1"
          connected: False
          state: absent
        - label: "Network adapter 1"
          state: new
          connected: True
          name: Vlan_13

This playbook deletes the present network adapter and the it adds the new adapter instead. i couldnt find a way to change. only delete and add.

Batchen Regev
  • 685
  • 1
  • 7
  • 28