-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_instance.yml
43 lines (39 loc) · 1.34 KB
/
create_instance.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
- hosts: localhost
connection: local
gather_facts: False
vars:
guest_name: test-mao
vmware_template: rhel7-vmw
tasks:
- name: create the instance
vsphere_guest:
validate_certs: no
vcenter_hostname: "{{ lookup('env', 'VMWARE_HOST') }}"
username: "{{ lookup('env', 'VMWARE_USER') }}"
password: "{{ lookup('env', 'VMWARE_PASSWORD') }}"
guest: "{{ guest_name }}"
from_template: yes
template_src: "{{ vmware_template }}"
vm_extra_config:
folder: testvms
esxi:
datacenter: DC01
hostname: 192.168.0.50
- name: loop until the guest has an IP address
vsphere_guest:
validate_certs: no
vcenter_hostname: "{{ lookup('env', 'VMWARE_HOST') }}"
username: "{{ lookup('env', 'VMWARE_USER') }}"
password: "{{ lookup('env', 'VMWARE_PASSWORD') }}"
guest: "{{ guest_name }}"
vmware_guest_facts: yes
register: instance
until: instance.ansible_facts.hw_eth0['ipaddresses']
retries: 30
delay: 10
- debug: var=instance
- name: save the instance IP
set_fact:
instance_ip: "{{ instance.ansible_facts.hw_eth0['ipaddresses'][0] }}"
- name: wait for ssh availability
local_action: wait_for host={{ instance_ip }} port=22 state=started delay=10