pyvmomi:无法在VmWare vSphere中设置IP地址

时间:2018-08-02 10:32:46

标签: python ansible vsphere pyvmomi

我使用此剧本,它通过模板创建新的VM,但我不知道使用IP和DNS配置的方式。我有想念的东西吗?

# 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

2 个答案:

答案 0 :(得分:1)

我不认为Debian实际上支持自定义。参见:http://partnerweb.vmware.com/programs/guestOS/guest-os-customization-matrix.pdf

但是,此问题上有一些故障排除步骤:https://github.com/ansible/ansible/issues/37198

答案 1 :(得分:1)

作为一种解决方法,请通过操作系统更改IP,但请事先检查VMWare工具是否可用:

因此,使用DHCP创建虚拟机:

a1*x1 + a2*x2 + a3*x3 + ... + an*xn = b

一旦您的虚拟机可用,请使用vmware_vm_shell:

- hosts: localhost
  gather_facts: False
  connection: local

  tasks:
  - name: Create VM
    vmware_guest:

  - name: Wait for VMware tools
    vmware_guest_tools_wait:

如果是Linux:

- 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