diff --git a/ansible/playbooks/openstack-vms.yml b/ansible/playbooks/openstack-vms.yml new file mode 100644 index 0000000..8993c7a --- /dev/null +++ b/ansible/playbooks/openstack-vms.yml @@ -0,0 +1,244 @@ +--- +- hosts: localhost + vars_files: + - ../vars/common.yml + - ../vars/{{ project_zone }}.yml + tasks: + - name: Create workbench VMs (ASYNCHRONUS) + os_server: + name: "{{ os_project }}-{{ win_project }}-wb{{ '%02d' | format(item+1) }}" + state: "{{ state }}" + image: c5d5abb3-c15a-4870-b9b7-89873ae9a9a6 + flavor: 3661211f-673a-4777-8857-fd243d6c407d + timeout: 900 + boot_from_volume: true + volume_size: 40 + terminate_volume: yes + security_groups: + - domain_member + - user_vms + network: "{{ os_network }}" + metadata: + name: "wb{{ '%02d' | format(item+1) }}" + win_project: "{{ win_project }}" + type: client + variant: workbench + userdata: | + #ps1 + Rename-Computer "ab-ansible-no-user" + $admin = [adsi]("WinNT://./Administrator, user") + $admin.PSBase.Invoke("SetPassword", "{{ vm_initial_password }}") + Invoke-Expression ((New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/ansible/ansible-documentation/devel/examples/scripts/ConfigureRemotingForAnsible.ps1')) + loop: "{{ range(wb_quantity)|list}}" + async: 900 + poll: 0 + register: async_wb + when: 'wb_quantity|int <= 5' + + - name: Create workbench VMs (SEQUENTIAL) + os_server: + name: "{{ os_project }}-{{ win_project }}-wb{{ '%02d' | format(item+1) }}" + state: "{{ state }}" + image: c5d5abb3-c15a-4870-b9b7-89873ae9a9a6 + flavor: 3661211f-673a-4777-8857-fd243d6c407d + timeout: 900 + boot_from_volume: true + volume_size: 40 + terminate_volume: yes + security_groups: + - domain_member + - user_vms + network: "{{ os_network }}" + metadata: + name: "wb{{ '%02d' | format(item+1) }}" + win_project: "{{ win_project }}" + type: client + variant: workbench + userdata: | + #ps1 + Rename-Computer "ab-ansible-no-user" + $admin = [adsi]("WinNT://./Administrator, user") + $admin.PSBase.Invoke("SetPassword", "{{ vm_initial_password }}") + Invoke-Expression ((New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/ansible/ansible-documentation/devel/examples/scripts/ConfigureRemotingForAnsible.ps1')) + loop: "{{ range(wb_quantity)|list}}" + when: 'async_wb.skipped == true' + + - name: Wait for workbench VMs to build + os_server_info: + name: "{{ os_project }}-{{ win_project }}-wb*" + filters: + vm_state: active + register: wb_status + until: 'wb_status.servers|length == wb_quantity|int' + retries: 100 + delay: 60 + when: 'async_wb.skipped == false' + + - name: Create application VMs (ASYNCHRONUS) + os_server: + name: "{{ os_project }}-{{ win_project }}-app{{ '%02d' | format(item+1) }}" + state: "{{ state }}" + image: c5d5abb3-c15a-4870-b9b7-89873ae9a9a6 + flavor: 3661211f-673a-4777-8857-fd243d6c407d + timeout: 900 + boot_from_volume: true + volume_size: 40 + terminate_volume: yes + security_groups: + - domain_member + - user_vms + network: "{{ os_network }}" + metadata: + name: "app{{ '%02d' | format(item+1) }}" + win_project: "{{ win_project }}" + type: client + variant: application + userdata: | + #ps1 + Rename-Computer "ab-ansible-no-user" + $admin = [adsi]("WinNT://./Administrator, user") + $admin.PSBase.Invoke("SetPassword", "{{ vm_initial_password }}") + Invoke-Expression ((New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/ansible/ansible-documentation/devel/examples/scripts/ConfigureRemotingForAnsible.ps1')) + loop: "{{ range(app_quantity)|list}}" + async: 900 + poll: 0 + register: async_app + when: 'app_quantity|int <= 5' + + - name: Create application VMs (SEQUENTIAL) + os_server: + name: "{{ os_project }}-{{ win_project }}-app{{ '%02d' | format(item+1) }}" + state: "{{ state }}" + image: c5d5abb3-c15a-4870-b9b7-89873ae9a9a6 + flavor: 3661211f-673a-4777-8857-fd243d6c407d + timeout: 900 + boot_from_volume: true + volume_size: 40 + terminate_volume: yes + security_groups: + - domain_member + - user_vms + network: "{{ os_network }}" + metadata: + name: "app{{ '%02d' | format(item+1) }}" + win_project: "{{ win_project }}" + type: client + variant: application + userdata: | + #ps1 + Rename-Computer "ab-ansible-no-user" + $admin = [adsi]("WinNT://./Administrator, user") + $admin.PSBase.Invoke("SetPassword", "{{ vm_initial_password }}") + Invoke-Expression ((New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/ansible/ansible-documentation/devel/examples/scripts/ConfigureRemotingForAnsible.ps1')) + loop: "{{ range(app_quantity)|list}}" + when: 'async_app.skipped == true' + + - name: Wait for application VMs to build + os_server_info: + name: "{{ os_project }}-{{ win_project }}-app*" + filters: + vm_state: active + register: app_status + until: 'app_status.servers|length == app_quantity|int' + retries: 100 + delay: 60 + when: 'async_app.skipped == false' + + - name: Create GPU VMs (ASYNCHRONUS) + os_server: + name: "{{ os_project }}-{{ win_project }}-gpu{{ '%02d' | format(item+1) }}" + state: "{{ state }}" + image: c5d5abb3-c15a-4870-b9b7-89873ae9a9a6 + flavor: 3661211f-673a-4777-8857-fd243d6c407d + timeout: 900 + boot_from_volume: true + volume_size: 40 + terminate_volume: yes + security_groups: + - domain_member + - user_vms + network: "{{ os_network }}" + metadata: + name: "gpu{{ '%02d' | format(item+1) }}" + win_project: "{{ win_project }}" + type: client + variant: gpu + userdata: | + #ps1 + Rename-Computer "ab-ansible-no-user" + $admin = [adsi]("WinNT://./Administrator, user") + $admin.PSBase.Invoke("SetPassword", "{{ vm_initial_password }}") + Invoke-Expression ((New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/ansible/ansible-documentation/devel/examples/scripts/ConfigureRemotingForAnsible.ps1')) + loop: "{{ range(gpu_quantity)|list}}" + async: 900 + poll: 0 + register: async_gpu + when: 'gpu_quantity|int <= 5' + + - name: Create GPU VMs (SEQUENTIAL) + os_server: + name: "{{ os_project }}-{{ win_project }}-gpu{{ '%02d' | format(item+1) }}" + state: "{{ state }}" + image: c5d5abb3-c15a-4870-b9b7-89873ae9a9a6 + flavor: 3661211f-673a-4777-8857-fd243d6c407d + timeout: 900 + boot_from_volume: true + volume_size: 40 + terminate_volume: yes + security_groups: + - domain_member + - user_vms + network: "{{ os_network }}" + metadata: + name: "gpu{{ '%02d' | format(item+1) }}" + win_project: "{{ win_project }}" + type: client + variant: gpu + userdata: | + #ps1 + Rename-Computer "ab-ansible-no-user" + $admin = [adsi]("WinNT://./Administrator, user") + $admin.PSBase.Invoke("SetPassword", "{{ vm_initial_password }}") + Invoke-Expression ((New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/ansible/ansible-documentation/devel/examples/scripts/ConfigureRemotingForAnsible.ps1')) + loop: "{{ range(gpu_quantity)|list}}" + when: 'async_gpu.skipped == true' + + - name: Wait for GPU VMs to build + os_server_info: + name: "{{ os_project }}-{{ win_project }}-gpu*" + filters: + vm_state: active + register: gpu_status + until: 'gpu_status.servers|length == gpu_quantity|int' + retries: 100 + delay: 60 + when: 'async_gpu.skipped == false' + + + - name: Create Common VMs (DCs, Fileservers, WSUS, Chocolatey) + openstack.cloud.server: + name: "{{ item.name }}" + state: "{{ state }}" + image: c5d5abb3-c15a-4870-b9b7-89873ae9a9a6 + flavor: 3661211f-673a-4777-8857-fd243d6c407d + timeout: 900 + boot_from_volume: true + volume_size: 40 + terminate_volume: yes + security_groups: + - domain_member + - "{{ item.security_group }}" + network: "{{ os_network }}" + metadata: + name: "{{ item.meta_name }}" + win_project: "{{ win_project }}" + type: server + variant: "{{ item.security_group }}" # just happens to match maybe change??? + userdata: | + #ps1 + Rename-Computer "ab-ansible-no-user" + $admin = [adsi]("WinNT://./Administrator, user") + $admin.PSBase.Invoke("SetPassword", "{{ vm_initial_password }}") + Invoke-Expression ((New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/ansible/ansible-documentation/devel/examples/scripts/ConfigureRemotingForAnsible.ps1')) + loop: "{{ standard_vms }}" + # Add async to this task for speed. can openstack handle 6 at once or split 3 3??? \ No newline at end of file