码迷,mamicode.com
首页 > 其他好文 > 详细

ansible并行创建vm虚拟机

时间:2019-07-16 18:02:42      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:使用   from   pre   延迟   path   als   OLE   network   xls   

之前的脚本是串行的,效率并不高
更改为并行模式

tree
.
├── ansible.cfg
├── create_vm
├── linux-vm-template
├── linux-vm-template.retry
├── roles
│?? ├── create_vm
│?? │?? └── tasks
│?? │??     └── main
│?? ├── linux_vm_template
│?? │?? └── tasks
│?? │??     └── main
│?? └── win_vm_template
│??     └── tasks
│??         └── main
├── vcenter.yml
├── vm-to-deploy
├── vm_list
├── vm_list.py
├── vm_list.xlsx
├── win2012-vm-template

ansible.cfg

[defaults]

# some basic default values...
library        = ./library

# additional paths to search for roles in, colon separated
roles_path    = ./roles

linux-vm-template

---
- hosts: all
  gather_facts: false
  vars_files:
    - vcenter.yml
  roles:
     - linux_vm_template

linux-vm-template task

---
---
- name: Create a virtual machine from a template
  vmware_guest:
    hostname: "{{vcenterhostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: no
    folder: /
    datacenter: "{{datacenter}}"
    name: "{{ ip }}_{{ hostname }}"
    state: poweredon
    esxi_hostname: "{{esxi_hostname}}"
    template: "{{os_version}}"
    disk:
    - size_gb: 51
      type: eagerzeroedthick    ## eagerzeroedthick厚置备零延迟   thin 精简置备
      datastore: "{{datastore}}"  ##存储
    - size_gb: "{{ datasize }}"
      #type: eagerzeroedthick
      datastore: "{{datastore}}"
    hardware:
      hotadd_cpu: true
      hotremove_cpu: true
      hotadd_memory: true
      memory_mb: "{{memory_mb}}"
      num_cpus: "{{num_cpus}}"
      scsi: lsilogic  ##linux用lsilogic,win用lsilogicsas,  默认使用paravirtual  这是VMware自己的准虚拟
    networks:
    - name: "{{vlan}}"  ##网络名
      device_type: vmxnet3  ## win使用e1000e
      ip: "{{ip}}"
      netmask: 255.255.255.0
      gateway: "{{gw}}"
    customization:
      hostname: "{{ hostname }}"
      dns_servers:
      - "{{dns1}}"
      - "{{dns2}}"
    wait_for_ip_address: no
  delegate_to: localhost
  register: deploy

inventory

10.20.14.69_disktest esxi_hostname=10.20.10.56 datastore=56_Localdisk d1_size_gb=50 d2_size_gb=100 memory_mb=16384 num_cpus=8 ip=10.20.14.69 gw=10.20.14.1 dns1=10.20.10.12 dns2=10.20.10.13 vlan=vlan14 hostname=disktest sys_ver=centos6_moban

使用

ansible-playbook -i inventory linux-vm-template

再通过ansible api 添加到django 界面,效率大大提升

技术图片

ansible并行创建vm虚拟机

标签:使用   from   pre   延迟   path   als   OLE   network   xls   

原文地址:https://blog.51cto.com/qingwa/2420791

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!