Last active
April 2, 2019 14:41
-
-
Save servo56/bf185204d04a9b78217be0dbb5042a9c to your computer and use it in GitHub Desktop.
Combined Build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description | |
# =========== | |
# Modified Azure Build for DC's by @vm_jmcminn jason.mcminn@shakerinternational.com and joe.harris@shakerinternational.com | |
# This playbook originally comes from @jborean93 (https://github.com/jborean93/ansible-win-demos) | |
# | |
- name: provision new azure host | |
hosts: localhost | |
connection: local | |
vars: | |
resource_group: "{{resource_group_name}}" | |
vm_name: '{{servername}}' | |
vm_user: xxxx | |
vm_password: xxxx | |
location: eastus2 | |
# st-act: devstgu1daiis{{number}} | |
network_resource_group: "{{network_resource_group_name}}" | |
vm_os_type: "{{vm_os_type_form_tower}}" | |
vm_subnet_name: "{{vm_subnet_name_from_tower}}" | |
vm_private_ip: "{{vm_private_ip_from_tower}}" | |
path_to_csv: "{{path_to_csv_from_tower}}" | |
# Below is UTF-16 Base64 encoding for: | |
# Invoke-Expression -Command ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1')); Enable-WSManCredSSP -Role Server -Force | |
winrm_enable_script: SQBuAHYAbwBrAGUALQBFAHgAcAByAGUAcwBzAGkAbwBuACAALQBDAG8AbQBtAGEAbgBkACAAKAAoAE4AZQB3AC0ATwBiAGoAZQBjAHQAIABTAHkAcwB0AGUAbQAuAE4AZQB0AC4AVwBlAGIAQwBsAGkAZQBuAHQAKQAuAEQAbwB3AG4AbABvAGEAZABTAHQAcgBpAG4AZwAoACcAaAB0AHQAcABzADoALwAvAHIAYQB3AC4AZwBpAHQAaAB1AGIAdQBzAGUAcgBjAG8AbgB0AGUAbgB0AC4AYwBvAG0ALwBhAG4AcwBpAGIAbABlAC8AYQBuAHMAaQBiAGwAZQAvAGQAZQB2AGUAbAAvAGUAeABhAG0AcABsAGUAcwAvAHMAYwByAGkAcAB0AHMALwBDAG8AbgBmAGkAZwB1AHIAZQBSAGUAbQBvAHQAaQBuAGcARgBvAHIAQQBuAHMAaQBiAGwAZQAuAHAAcwAxACcAKQApADsAIABFAG4AYQBiAGwAZQAtAFcAUwBNAGEAbgBDAHIAZQBkAFMAUwBQACAALQBSAG8AbABlACAAUwBlAHIAdgBlAHIAIAAtAEYAbwByAGMAZQA= | |
tasks: | |
- name: get network facts | |
azure_rm_virtualnetwork_facts: | |
resource_group: "{{ network_resource_group }}" | |
register: facts | |
- debug: | |
msg: 'Facts that came back: {{ facts }}' | |
# - name: get ip address from csv file | |
# read_csv: | |
# path: "{{ path_to_csv }}" | |
# key: "{{ vm_name }}" | |
# register: vm_ip_addresses | |
- name: create new NIC | |
azure_rm_networkinterface: | |
name: '{{ vm_name }}-nic' | |
os_type: '{{ vm_os_type }}' | |
resource_group: "{{ resource_group }}" | |
virtual_network_name: "{{ facts.ansible_facts.azure_virtualnetworks[0].id }}" | |
subnet_name: "{{ vm_subnet_name }}" | |
security_group_name: | |
ip_configurations: | |
- name: default | |
private_ip_allocation_method: Static | |
private_ip_address: "{{vm_private_ip_from_tower}}" | |
public_ip_address_name: | |
# private_ip_address: "{{ vm_private_ip }}" # when taking this info from tower, uncomment this line | |
# private_ip_address: "{{ vm_ip_addresses.dict.{{ vm_name }}.ip }}" # when read form csv file. you will need to figure out how to actually make this work | |
- name: provision new Azure virtual host | |
azure_rm_virtualmachine: | |
admin_username: '{{ vm_user }}' | |
admin_password: "{{ vm_password }}" | |
managed_disk_type: Premium_LRS | |
os_type: Windows | |
image: | |
offer: WindowsServer | |
publisher: MicrosoftWindowsServer | |
sku: 2016-Datacenter | |
version: latest | |
name: "{{ vm_name }}" | |
network_interface_names: '{{ vm_name }}-nic' | |
resource_group: "{{ resource_group }}" | |
state: present | |
vm_size: "{{vmsize}}" | |
data_disks: | |
- lun: 0 | |
disk_size_gb: 1023 | |
managed_disk_type: Premium_LRS | |
# storage_account_name: teststoreacctu1 | |
# virtual_network_name: "TEST-NET" | |
# subnet_name: "U1-TA-NET" | |
- name: create Azure vm extension to enable HTTPS WinRM listener | |
azure_rm_virtualmachine_extension: | |
name: winrm-extension | |
resource_group: "{{ resource_group }}" | |
virtual_machine_name: "{{ vm_name }}" | |
publisher: Microsoft.Compute | |
virtual_machine_extension_type: CustomScriptExtension | |
type_handler_version: 1.9 | |
settings: '{"commandToExecute": "powershell.exe -ExecutionPolicy ByPass -EncodedCommand {{winrm_enable_script}}"}' | |
auto_upgrade_minor_version: true | |
- name: wait for the WinRM port to come online | |
wait_for: | |
port: 5986 | |
host: '{{ansbilehostname}}' | |
timeout: 600 | |
- name: Copy Scripts | |
win_copy: | |
src: /winscripts/ | |
dest: 'C:\Temp\' | |
remote_src: no | |
- name: Change Time and PageFile | |
win_command: powershell.exe -ExecutionPolicy ByPass -File C:/temp/runfirst.ps1 | |
- name: Setup New Page File | |
win_command: powershell.exe -ExecutionPolicy ByPass -File C:/temp/runsecond.ps1 | |
- name: Setup Data Drive | |
win_command: powershell.exe -ExecutionPolicy ByPass -File C:/temp/new1tb.ps1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment