mirror of
https://git.ecdf.ed.ac.uk/win_automation/windows-ansible.git
synced 2026-10-26 19:57:21 +00:00
55 lines
1.8 KiB
YAML
55 lines
1.8 KiB
YAML
---
|
|
- name: Create gpu VMs (SEQUENTIAL)
|
|
vars:
|
|
vm_name: "{{ os_project }}-{{ win_project }}-gpu{{ '%02d' | format(item+1+gpu_quantity|int) }}"
|
|
os_server:
|
|
name: "{{ vm_name }}"
|
|
state: "{{ state }}"
|
|
image: "{{ vm_image }}"
|
|
flavor: "{{ user_vm_flavor }}"
|
|
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+gpu_quantity|int) }}"
|
|
win_project: "{{ win_project }}"
|
|
type: client
|
|
variant: gpu
|
|
os: windows
|
|
new_vm: "true" # Tag to target only new VMs
|
|
userdata: |
|
|
#ps1
|
|
Rename-Computer "{{ win_project }}-gpu{{ '%02d' | format(item+1+gpu_quantity|int) }}"
|
|
$admin = [adsi]("WinNT://./Administrator, user")
|
|
$admin.PSBase.Invoke("SetPassword", "{{ vm_initial_password }}")
|
|
Invoke-Expression ((New-Object System.Net.Webclient).DownloadString('{{ winrm_script_url }}'))
|
|
when:
|
|
- "vm_name not in groups['meta-type_client']|default([])"
|
|
- cleanup == 'false'
|
|
loop: "{{ range(new_gpu_quantity|int)|list }}"
|
|
|
|
- name: cleanup
|
|
block:
|
|
- name: delete metadata from instance
|
|
vars:
|
|
vm_name: "{{ os_project }}-{{ win_project }}-gpu{{ '%02d' | format(item+1+gpu_quantity|int) }}"
|
|
openstack.cloud.server_metadata:
|
|
state: absent
|
|
cloud: "{{ os_project }}"
|
|
name: "{{ vm_name }}"
|
|
meta:
|
|
new_vm:
|
|
loop: "{{ range(new_gpu_quantity|int)|list }}"
|
|
|
|
- name: Increase gpu quantity variable
|
|
ansible.builtin.lineinfile:
|
|
path: /deployments/{{ os_project }}-{{ win_project }}/ansible/vars/common.yml
|
|
regexp: '^gpu_quantity:\s*\d+'
|
|
line: "gpu_quantity: {{ gpu_quantity + new_gpu_quantity | int }}"
|
|
when: cleanup == 'true'
|