-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm.yml_bck2
211 lines (211 loc) · 6.88 KB
/
vm.yml_bck2
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
---
#import requests
- hosts: vm
# tasks:
#connection: local
# gather_facts: ture
vars_prompt:
- name: myuser
prompt: Enter the UserName
private: no
- name: mypass
prompt: Enter the Password
- name: vc_name
prompt: Enter the vCenter/ESXi HostName
private: no
- name: guest_name
prompt: Enter the Guest VM Name
private: no
- name: hdd
prompt: Enter the HardDrive Space you want to use by default 50 is for windows an 16 is for linux
private: no
- name: ram
prompt: Enter the RAM in MB by default 2048 MB
private: no
- name: cpu
prompt: Enter the number of processor you want to use by default 2
private: no
- name: ip_addr
prompt: Enter the Ip address you want to specify
private: no
- name: vm_gateway
prompt: Enter the default gateway
private: no
- name: guest_password
prompt: Enter the guest password
# tasks:
# - name: vm_password_new
# prompt: Enter new password for the system
# tasks:
# - name: choose_os
# command: ls/vmfs/volumes/datastore1/Iso
- name: os_system
private: no
prompt: |
Which os do you want to use?
1- Windows Server
2- CentOS_7
3- CentOs_8
4- Ubuntu
5- Others
tasks:
- name: Creation of Machine
# when: (os_system == "1")
# no network
vmware_deploy_ovf:
#shared_path: //172.31.254.248/Users/Administrator/Desktop/ovf
hostname: '{{ vc_name }}'
username: '{{ myuser }}'
password: '{{ mypass }}'
name: '{{ guest_name }}'
datacenter: ha-datacenter
datastore: datastore1
validate_certs: no
ovf: /home/prashant/windows_server/windows_server.ovf
# ovf: /mnt/c/users/thinkpad/desktop/windows_server/windows_server.ovf
# wait_for_ip_ address: yes
power_on: yes
when: (os_system == "1")
delegate_to: localhost
- name: install vmware tools via Chocolatey
tags: tools
name: '{{ guest_name }}'
# hostname: '{{ vc_name }}'
# username: '{{ myuser }}'
# password: '{{ mypass }}'
# vm_username: Administrator
# validate_certs: no
# vm_password: '{{ guest_password }}'
win_chocolatey: name=vmware-tools state=present
when: ansible_os_family == "Windows"
- name: configure ip-address
# local_action:
vmware_vm_shell:
hostname: '{{ vc_name }}'
username: '{{ myuser }}'
password: '{{ mypass }}'
vm_username: Administrator
validate_certs: no
vm_password: '{{ guest_password }}'
vm_id: '{{ guest_name }}'
vm_shell: 'c:\windows\system32\windowspowershell\v1.0\powershell.exe'
vm_shell_args: '-command "(new-netipaddress -InterfaceAlias Ethernet0 -IPAddress {{ ip_addr }} -prefixlength 24 -defaultgateway {{ vm_gateway }})"'
when: (os_system == "1")
delegate_to: localhost
- name: configure Dns
# local_action:
vmware_vm_shell:
hostname: '{{ vc_name }}'
username: '{{ myuser }}'
password: '{{ mypass }}'
validate_certs: no
vm_username: Administrator
vm_password: '{{ guest_password }}'
vm_id: '{{ guest_name }}'
vm_shell: 'c:\windows\system32\windowspowershell\v1.0\powershell.exe'
vm_shell_args: '-command "(Set-DnsClientServerAddress -InterfaceAlias Ethernet0 -ServerAddress 8.8.8.8)"'
when: (os_system == "1")
delegate_to: localhost
- name: guests_facts
vmware_guest_info:
hostname: "{{ vc_name }}"
username: "{{ myuser }}"
password: "{{ mypass }}"
datacenter: ha-datacenter
validate_certs: no
name: "{{ guest_name }}"
delegate_to: localhost
register: facts
- name: disks_facts
vmware_guest_disk_facts:
hostname: "{{ vc_name }}"
username: "{{ myuser }}"
password: "{{ mypass }}"
datacenter: ha-datacenter
validate_certs: no
name: "{{ guest_name }}"
delegate_to: localhost
# when: os_system == "{{ os_system }}" and hdd > "{{ hdd }}"
# disk:
# size-gb: "{{ hdd }}"
# # type: thin
# datastore: datastore1
# when: ( ram > "2048" )
# state: poweredoff
# - hardware:
# memory_mb: "{{ ram }}"
# when: (cpu > "2")
# state: poweredoff
# - hardware:
# num_cpu: "{{ cpu }}"
delegate_to: localhost
- name: creation of machine
when: (os_system == "2")
vmware_deploy_ovf:
hostname: '{{ vc_name }}'
username: '{{ myuser }}'
password: '{{ mypass }}'
name: '{{ guest_name }}'
datacenter: ha-datacenter
datastore: datastore1
validate_certs: no
ovf: /mnt/c/users/thinkpad/desktop/root_test_mfa/root_test_mfa.ovf
# wait_for_ip_ address: yes
power_on: yes
delegate_to: localhost
name: configure ip-address
local_action:
vmware_vm_shell:
vm_username: root
vm_password: "{{ guest_password }}"
vm_id: "{{ guest_name }}"
vm_shell: /uer/bin/sudo
vm_shell_args: 'usr/sbin/ifconfig ens192 "{{ ip_addr }}" netmask 255.255.255.0 broadcast "" {{ vm_gateway }}"'
vm_shell_cwd: "/usr/sbin"
delegate_to: locahost
#tasks:
- name: hdd increase
tags: hdd
# when: (os_system == "{{ os_system }}" and hdd < "{{ hdd }}")
vmware_guest:
username: "{{ myuser }}"
hostname: "{{ vc_name }}"
name: "{{ guest_name }}"
password: "{{ mypass}}"
disk:
- size_gb: "{{ hdd }}"
type: thin
datastore: datastore1
datacenter: ha-datacenter
validate_certs: no
when: (hdd > "20")
delegate_to: localhost
- name: memory_increase
tags: hdd
# when: ( ram > "{{ #ram }})"
vmware_guest:
username: "{{myuser}}"
hostname: "{{ vc_name }}"
name: "{{ guest_name }}"
password: "{{ mypass }}"
state: poweredoff
hardware:
memory_mb: "{{ ram }}"
# datacenter: ha-datacenr
validate_certs: no
when: ( ram > "2048")
delegate_to: localhost
- name: cpu increase
tags: hdd
# when: ( cpu > " 2 " )
vmware_guest:
username: "{{ myuser }}"
hostname: "{{ vc_name }}"
name: "{{ guest_name }} "
password: "{{ mypass }}"
state: poweredoff
hardware:
num_cpu: "{{ cpu }}"
validate_certs: no
when: (cpu > "2")
delegate_to: localhost