Gilles Quénot
Gilles Quénot

Reputation: 185073

pyvmomi: can't set IP address in VmWare vSphere

I use this playbook, it create a new VM from a template, but I can't figure out the way to use the IP and DNS configuration. Is there something I miss ?

# Deploy a guest from a template*
- hosts: 127.0.0.1
  tasks:
  - name: Create a virtual machine
    vmware_guest:
      datacenter: xxx
      hostname: vcenter1.foobar.tld
      username: xxxx
      password: xxxx
      validate_certs: False
      folder: xxx/yyy/zzz
      name: TEST-01
      template: TEMPLATE-DEBIAN9
      cluster: cluster1
      state: poweredon
      hardware:
        memory_mb: 1024
        num_cpus: 1
      networks:
      - name: LAN_394_FOOBAR
        nic1:
          type: vmxnet3
          network_type: standard
      - name: WAN_432_FOOBAR
        nic2:
          type: vmxnet3
          network_type: standard
          ip: x.x.x.x
          netmask: 255.255.255.0
          gateway: x.x.x.x
          domain: foobar.tld
          dns_servers:
          - x.x.x.x
          - x.x.x.y

Upvotes: 0

Views: 3082

Answers (2)

imjoseangel
imjoseangel

Reputation: 3936

As a workaround, change the IP through the OS but checking if VMWare Tools are available beforehand:

So, using a DHCP, create your VM:

- hosts: localhost
  gather_facts: False
  connection: local

  tasks:
  - name: Create VM
    vmware_guest:

  - name: Wait for VMware tools
    vmware_guest_tools_wait:

Once you have your VM available use vmware_vm_shell:

- name: Set IP Address on Windows
  vmware_vm_shell:
    vm_shell       : netsh.exe
    vm_shell_args  : ' interface ip set address name="Ethernet0" static {{ network.subnet }}.{{ network.ip }} {{ network.netmask }} {{ network.subnet }}.1'
    vm_shell_cwd   : "C:\\Windows\\System32"

- name: Set DNS on Windows
  vmware_vm_shell:
    vm_shell       : netsh.exe
    vm_shell_args  : ' interface ip set dns name="Ethernet0" static {{ network.dns1 }}'
    vm_shell_cwd   : "C:\\Windows\\System32"

- name: Wait for WINRM port
  wait_for:
    port: 5986
    delay: 20
    state: started

If Linux:

- name: Set IP Address on Linux
  vmware_vm_shell:
    vm_shell       : /usr/bin/sudo
    vm_shell_args  : ' /usr/sbin/ifconfig eth0 {{ network.subnet }}.{{ net }} netmask {{ network.netmask }} up'
    vm_shell_cwd   : /usr/sbin

- name: Wait for SSH port
  wait_for:
    port: 22
    delay: 20
    state: started

Upvotes: 1

Kyle Ruddy
Kyle Ruddy

Reputation: 2121

I don't believe Debian is actually supported for customization. See: http://partnerweb.vmware.com/programs/guestOS/guest-os-customization-matrix.pdf

However, there are some troubleshooting steps available on this issue: https://github.com/ansible/ansible/issues/37198

Upvotes: 1

Related Questions