Guest User

Untitled

a guest
Jun 30th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. ---
  2. # vim: set ft=ansible et ts=2 sw=2:
  3. #
  4. # Create a new VM to kickstart install
  5.  
  6. - hosts: vmcreate
  7. gather_facts: false
  8. connection: local
  9. vars:
  10. vcenter_hostname: esx1.box
  11. esxhost: esx1.box
  12. vcenter_folder: "New Build"
  13. datastore: datastore1
  14. datacenter: ha-datacenter
  15. network: "VMnetwork"
  16. state: powered_on
  17. disksize: 20
  18. mem: 1024
  19. cpus: 1
  20. notes: Created by Ansible
  21. tasks:
  22. - name: Check for required variables
  23. fail: msg="Must pass name to -e"
  24. when: name is not defined
  25.  
  26. - name: Check for permission to run
  27. assert:
  28. that: allowed_to_deploy is true
  29.  
  30. - name: Check for vSphere access parameters
  31. fail: msg="Must set vcenter_user and vcenter_pass in a Vault"
  32. when: (vcenter_user is not defined) or (vcenter_pass is not defined)
  33.  
  34. - name: Create a new VM
  35. vsphere_guest:
  36. vcenter_hostname: "{{ vcenter_hostname }}"
  37. username: "{{ vcenter_user }}"
  38. password: "{{ vcenter_pass }}"
  39. guest: "{{ name }}"
  40. state: "{{ state }}"
  41. vm_extra_config:
  42. notes: "{{ notes }}"
  43. vm_disk:
  44. disk1:
  45. size_gb: "{{ disksize }}"
  46. type: thin
  47. datastore: "{{ datastore }}"
  48. vm_nic:
  49. nic1:
  50. type: vmxnet3
  51. network: "{{ network }}"
  52. network_type: standard
  53. # nic2:
  54. # type: vmxnet3
  55. # network: "Kickstart"
  56. # network_type: standard
  57. vm_hardware:
  58. memory_mb: "{{ mem }}"
  59. num_cpus: "{{ cpus }}"
  60. osid: centos64Guest
  61. scsi: paravirtual
  62. vm_cdrom:
  63. type: iso
  64. iso_path: "/ISOs/{{ iso | default('CentOS-6.6-x86_64-bin-DVD1.iso') }}"
  65. vm_hw_version: vmx-08
  66. esxi:
  67. datacenter: "{{ datacenter }}"
  68. hostname: "{{ esxhost }}"
  69.  
  70. - name: Gather VM facts
  71. vsphere_guest:
  72. vcenter_hostname: "{{ vcenter_hostname }}"
  73. username: "{{ vcenter_user }}"
  74. password: "{{ vcenter_pass }}"
  75. guest: "{{ name }}"
  76. vmware_guest_facts: yes
  77. register: newvm
  78. tags: mac
  79.  
  80. - name: Report VM MAC address
  81. debug: msg="{{ newvm.ansible_facts.hw_eth0.macaddress_dash }}"
  82. tags: mac
Add Comment
Please, Sign In to add comment