Ansible VMware模塊使用示例


vmware_vm_facts模塊使用示例

 

執行條件:

  安裝Pyvmimo:  pip install pyvmomi

 

方法一,直接編寫單個yaml文件:

- hosts: localhost   # 注意這里使用的是 localhost
  gather_facts: True  # 是否開啟或關閉收集遠程主機信息
  connection: local  

  tasks:
  - name: Gather Facts of all vms in vCenter Server
    local_action:
      module: vmware_vm_facts
      hostname: '10.110.164.133'
      username: 'administrator@vsphere.local'
      password: 'VMware1!'
      validate_certs: no
    register: vmfacts

  - name: Verbose virtual machine
    debug:
      msg: "{{ vmfacts.virtual_machines }}"

 

方法二,編寫playbook

1.目錄結構

├── get_vms.yaml

└── roles

    └── vc01

        └── tasks

            └── main.yaml

 

2. main.yaml內容

- name: vm
  vmware_vm_facts:
    hostname: '10.110.164.133'
    username: 'administrator@vsphere.local'
    password: 'VMware1!'
    validate_certs: no
  delegate_to: localhost  
  register: instance_vm_facts

- debug:
    var: instance_vm_facts.virtual_machines

3. get_vms.yaml

- hosts: localhost # 注意這里使用的是localhost 
  gather_facts: True
  roles:
  - vc01

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM