Advertisement
Guest User

Untitled

a guest
Jul 5th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.90 KB | None | 0 0
  1. ---
  2. - hosts: 127.0.0.1
  3.   connection: local
  4.   gather_facts: no
  5.   vars_prompt:
  6.     - name: "vsphere_user"
  7.       private: no
  8.       prompt: "vSphere/ESXi user"
  9.     - name: "vsphere_password"
  10.       private: yes
  11.       prompt: "vSphere/ESXi password"  
  12.     - name: "new_vm_name"
  13.       prompt: "New VM Name"
  14.       private: no
  15.     - name: "vm_password"
  16.       prompt: "New Admin Password"
  17.       private: no
  18.       default: "password"
  19.  
  20.   tasks:
  21.   - name: Deploy the VM
  22.     vmware_guest:
  23.       hostname: DMCISDCPPT37v.DMCI-ISF.COM
  24.       username: "{{ vsphere_user }}"
  25.       password: "{{ vsphere_password }}"
  26.       validate_certs: no
  27.       esxi_hostname: dmcisdnihv901.dmci-isf.com
  28.       datacenter: SDCP-DevOps
  29.       folder: /Demo
  30.       name: "{{ new_vm_name }}"
  31.       state: poweredon
  32.       template: win10-template
  33.  
  34.   - name: Wait for OOBE Completion and DHCP
  35.     pause:
  36.       seconds: 30
  37.  
  38.   - name: Attempt to gather accurate VM Guest facts
  39.     vmware_guest_facts:
  40.       datacenter: SDCP-DevOps
  41.       folder: /Demo
  42.       hostname: DMCISDCPPT37v.DMCI-ISF.COM
  43.       name: '{{ new_vm_name }}'
  44.       password: '{{ vsphere_password }}'
  45.       username: '{{ vsphere_user }}'
  46.       validate_certs: no
  47.     delegate_to: localhost
  48.     register: facts
  49.  
  50.   - name: Add new VM to inventory
  51.     add_host:
  52.       name: '{{facts.instance.ipv4}}'
  53.       ansible_connection: winrm
  54.       ansible_user: xAdministrator
  55.       ansible_password: "{{ vm_password }}"
  56.       ansible_winrm_transport: basic
  57.       ansible_winrm_server_cert_validation: ignore
  58.       groups: newvm
  59.     changed_when: false
  60.    
  61. - hosts: [newvm]
  62.   gather_facts: no
  63.   tasks:
  64.   - name: Wait for a connection
  65.     wait_for_connection:
  66.       delay: 180
  67.       sleep: 15
  68.       timeout: 600
  69.   - name: Reboot Machine
  70.     win_reboot:
  71.   - name: Wait for a connection
  72.     wait_for_connection:
  73.       delay: 60
  74.       sleep: 15
  75.       timeout: 600
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement