ansible - 尝试在ESXi上部署VM

时间:2016-08-09 06:14:10

标签: ansible

我仍然在使用ansible时遇到很多麻烦。耶稣这个工具让我生病... 但是,我有一个" .yml"文件名为" vmware2.yml" 所以在这本剧本中,我写了以下几行:

---
- hosts: localhost
  connection: local
  tasks:
- vsphere_guest:
    vcenter_hostname: emea-esx-s18t.sddc-hwl-family.net
    username: root
    password: HWL-sddc
    guest: newvm001
    state: powered_off
    vm_extra_config:
      vcpu.hotadd: yes
      mem.hotadd:  yes
      notes: This is a test VM
    vm_disk:
      disk1:
        size_gb: 10
        type: thin
        datastore: gmh-040-data-esx-sddc
    vm_nic:
      nic1:
        type: vmxnet3
        network: VM Network
        network_type: standard
    vm_hardware:
      memory_mb: 4096
      num_cpus: 4
      osid: windows7Server64Guest
      scsi: paravirtual
    esxi:
      datacenter: MyDatacenter
      hostname: esx-s18t.sddc-hwl-family.net

当我执行剧本时,我收到了以下消息:

root@ansible1:~/ansible# ansible-playbook vmware2.yml
ERROR! 'vsphere_guest' is not a valid attribute for a Play

The error appears to have been in '/root/ansible/vmware2.yml': line 5, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  tasks:
- vsphere_guest:
  ^ here

我过去曾问过这个问题 - > trouble with pysphere - ansible

所以似乎ESXi不知道模块或命令。因为我试图在那里执行它。 我只想在我的ESXi主机上通过Ansible部署VM ..

你能帮助我吗? :/

1 个答案:

答案 0 :(得分:0)

试试这个:

---
- hosts: localhost
  connection: local
  tasks:
    - vsphere_guest:
        vcenter_hostname: emea-esx-s18t.sddc-hwl-family.net
        username: root
        password: HWL-sddc
        guest: newvm001
        state: powered_off
        vm_extra_config:
          vcpu.hotadd: yes
          mem.hotadd:  yes
          notes: This is a test VM
        vm_disk:
          disk1:
            size_gb: 10
            type: thin
            datastore: gmh-040-data-esx-sddc
        vm_nic:
          nic1:
            type: vmxnet3
            network: VM Network
            network_type: standard
        vm_hardware:
          memory_mb: 4096
          num_cpus: 4
          osid: windows7Server64Guest
          scsi: paravirtual
        esxi:
          datacenter: MyDatacenter
          hostname: esx-s18t.sddc-hwl-family.net