簡體   English   中英

在 vSphere 中創建虛擬機的 Ansible playbook

[英]Ansible playbook to create VM in vSphere

我需要一個Ansible劇本來在我的vSphere 中創建一個虛擬機,這可能嗎?

為長時間的延遲回復道歉。 這是我用來在 vSphere 上創建新虛擬機的代碼。 我能夠成功創建一個新的虛擬機,但是當我嘗試“打開”虛擬機並嘗試連接到它時 - 它顯示一個空白屏幕,上面寫着“找不到操作系統”。

---
- name : To test VM creation on vSphere
  hosts  : localhost
  gather_facts : False
  tasks  :
   - name : Including Secrets
     include_vars:
             file: ../secrets.yml
             name: secret

   - name : Create a new vm from template
     vmware_guest :
        hostname: "{{secret.hostname}}"        
        user: "{{secret.username}}"
        password: "{{secret.password}}"
        validate_certs: no
        datacenter: "{{ datacenter }}"
        folder: /vm
        name: an-new-vm
        state: poweredon
        guest_id: centos64Guest
        esxi_hostname: "{{ hostname }}"
        customization:
             autologon: True
             existing_vm: True
        hardware: 
            num_cpus: 2
            memory_mb: 8192
        disk:
           - size_gb: 40
             datastore: datastore-2
        networks:
        - name: VM Network
          type: dhcp
          device_type: vmxnet3
          hostname: ansible-testing.domain.da
          allow_guest_control: True
          wait_for_ip_address: yes
     register : new_vm

   - debug:
       var: new_vm

只是想檢查我是否需要向它提供 ISO 文件? 從現有 VM 克隆 VM 工作正常,甚至從模板克隆也工作正常。 即使我提供了guest_id ,我也只是檢查guest_id因為具有相應版本的操作系統的某些風味不足以啟動和運行guest_id 如果我必須使用下面的ansibleplaybook.yml文件提供 ISO 文件,那么我怎么能通過它呢?

您創建了一個新的 VM(沒有操作系統),您收到錯誤是正常的: NO OS FOUND

嘗試這個:

---
- name : To test VM creation on vSphere
  hosts  : localhost
  gather_facts : False
  tasks  :
   - name : Including Secrets
     include_vars:
             file: ../secrets.yml
             name: secret

   - name : Create a new vm from template
     vmware_guest :
        hostname: "{{secret.hostname}}"        
        user: "{{secret.username}}"
        password: "{{secret.password}}"
        validate_certs: no
        datacenter: "{{ datacenter }}"
        folder: /vm
        name: an-new-vm
        state: poweredon
        guest_id: centos64Guest
        esxi_hostname: "{{ hostname }}"
        cdrom:
        - iso_path: "{{ [datastore1]path/to/file.iso }}"
          type: iso 
        customization:
             autologon: True
             existing_vm: True
        hardware: 
            num_cpus: 2
            memory_mb: 8192
        disk:
           - size_gb: 40
             datastore: datastore-2
        networks:
        - name: VM Network
          type: dhcp
          device_type: vmxnet3
          hostname: ansible-testing.domain.da
          allow_guest_control: True
          wait_for_ip_address: yes
     register : new_vm

   - debug:
       var: new_vm

有關更多信息,請參閱此鏈接: https : //docs.ansible.com/ansible/latest/collections/community/vmware/vmware_guest_module.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM