-
Notifications
You must be signed in to change notification settings - Fork 1
/
wip.yml
175 lines (157 loc) · 6.47 KB
/
wip.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
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
---
- name: Guest Creation
gather_facts: no
vars_files:
- vcenter_vars.yml
hosts: localhost
tasks:
- name: Clone a virtual machine {{ vm_name }} from existing template {{ template_name }}
vmware_guest:
name: "{{ vm_name }}"
template: "{{ template_name_win }}"
hostname: "{{ vcenter_server }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
state: present
validate_certs: no
folder: "{{ folder }}"
datacenter: "{{ datacenter_2 }}"
# convert: thin
networks:
- name: "{{ network }}"
start_connected: True
type: static
device_type: e1000e
ip: 10.118.77.113
netmask: 255.255.255.192
- name: "{{ network_2 }}"
start_connected: True
type: static
device_type: e1000e
ip: 168.1.95.182
netmask: 255.255.255.240
gateway: 168.1.95.177
cluster: "{{ cluster_2 }}"
disk:
- size_gb: "{{ vm_storage_size }}"
type: thin
autoselect_datastore: True
hardware:
memory_mb: "{{ vm_memory_size }}"
num_cpus: "{{ vm_number_of_cpu }}"
customization:
dns_servers:
- 10.118.77.68
- 10.0.80.11
password: RedHat1!
timezone: 260
wait_for_ip_address: yes
register: vm_result
- pause: seconds=180
- name: Wait for VMware tools to become available by name
vmware_guest_tools_wait:
hostname: "{{ vcenter_server }}"
username: [email protected]
password: "{{ vcenter_pass }}"
validate_certs: no
name: "{{ vm_name }}"
- name: change computer name to target vm name
vmware_vm_shell:
hostname: "{{ vcenter_server }}"
username: [email protected]
password: "{{ vcenter_pass }}"
validate_certs: false
wait_for_process: True
datacenter: "{{ datacenter_2 }}"
vm_id: "{{ vm_name }}"
vm_username: "{{ vmwin_adminuser }}"
vm_password: "{{ vmwin_adminpassword }}"
vm_shell: 'c:\windows\system32\windowspowershell\v1.0\powershell.exe'
vm_shell_args: '-Command (Rename-Computer -NewName {{ vm_name }} -Force )'
- pause: seconds=10
- name: Add Static Routes
vmware_vm_shell:
hostname: "{{ vcenter_server }}"
username: [email protected]
password: "{{ vcenter_pass }}"
validate_certs: false
datacenter: "{{ datacenter_2 }}"
wait_for_process: True
vm_id: "{{ vm_name }}"
vm_username: "{{ vmwin_adminuser }}"
vm_password: "{{ vmwin_adminpassword }}"
vm_shell: 'c:\windows\system32\windowspowershell\v1.0\powershell.exe'
vm_shell_args: "{{ item }}"
with_items:
- '-command "& {route -p ADD 10.0.0.0 MASK 255.0.0.0 10.118.77.65}"'
# - '-command "& {route -p ADD 0.0.0.0 MASK 0.0.0.0 168.1.95.177}"'
- pause: seconds=10
- name: Enable WinRM to be used with Ansible
vmware_vm_shell:
hostname: "{{ vcenter_server }}"
username: [email protected]
password: "{{ vcenter_pass }}"
validate_certs: false
datacenter: "{{ datacenter_2 }}"
wait_for_process: True
vm_id: "{{ vm_name }}"
vm_username: Administrator
vm_password: "{{ vmwin_adminpassword }}"
vm_shell: 'c:\windows\system32\windowspowershell\v1.0\powershell.exe'
vm_shell_args: "{{ item }}"
with_items:
- '-command "& {Set-ExecutionPolicy Unrestricted}"'
- '-command "& {Invoke-Expression ((New-Object System.Net.Webclient).DownloadString(\"https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1\"))}"'
- '-command "& {Set-ExecutionPolicy RemoteSigned}"'
- pause: seconds=10
- name: join to AD domain
vmware_vm_shell:
hostname: "{{ vcenter_server }}"
username: [email protected]
password: "{{ vcenter_pass }}"
validate_certs: false
datacenter: "{{ datacenter_2 }}"
vm_id: "{{ vm_name }}"
# wait_for_process: True
vm_username: "{{ vmwin_adminuser }}"
vm_password: "{{ vmwin_adminpassword }}"
vm_shell: 'c:\windows\system32\windowspowershell\v1.0\powershell.exe'
vm_shell_args: "{{ item }}"
with_items:
- '-Command "& {$pwd = ConvertTo-SecureString -AsPlainText -Force \"{{ vmwin_ad_adminpassword }}\" ; $cred = New-Object System.Management.Automation.PSCredential(\"{{ vmwin_ad_domain }}\{{ vmwin_ad_adminuser }}\",$pwd) ; Add-Computer -Domain {{ vmwin_ad_domain }} -Credential $cred ; Restart-Computer}"'
- pause: seconds=10
# - name: Execute Security Powershell - test
# vmware_vm_shell:
# hostname: "{{ vcenter_server }}"
# username: [email protected]
# password: "{{ vcenter_pass }}"
# validate_certs: false
# datacenter: "{{ datacenter_2 }}"
# wait_for_process: True
# vm_id: "{{ vm_name }}"
# vm_username: Administrator
# vm_password: "{{ vmwin_adminpassword }}"
# vm_shell: 'c:\windows\system32\windowspowershell\v1.0\powershell.exe'
# vm_shell_args: "{{ item }}"
# with_items:
# - '-command "& {Set-ExecutionPolicy Unrestricted}"'
# - '-command "& {Invoke-Expression ((New-Object System.Net.Webclient).DownloadString(\"http://168.1.95.186/powershell/test.ps1\"))}"'
# - '-command "& {Set-ExecutionPolicy RemoteSigned}"'
- pause: seconds=120
- name: 5G Security Policy
vmware_vm_shell:
hostname: "{{ vcenter_server }}"
username: [email protected]
password: "{{ vcenter_pass }}"
validate_certs: false
datacenter: "{{ datacenter_2 }}"
wait_for_process: True
vm_id: "{{ vm_name }}"
vm_username: "{{ vmwin_adminuser }}"
vm_password: "{{ vmwin_adminpassword }}"
vm_shell: 'c:\windows\system32\windowspowershell\v1.0\powershell.exe'
vm_shell_args: "{{ item }}"
with_items:
- '-command "& {Set-ExecutionPolicy Unrestricted}"'
- '-command "& {Invoke-Expression ((New-Object System.Net.Webclient).DownloadString(\"http://168.1.95.186/powershell/call.ps1\"))}"'
- '-command "& {Set-ExecutionPolicy RemoteSigned}"'