I'm deploying a Windows Instance in GCP with couple of startup scripts using the metadata option in the gcp_compute_instance module, as the instance is getting created as expected but the startup scripts are not getting executing, kindly refer the below task and do suggest what changes I need to do to execute the startup script (first creating a local admin user with password and then setting winrm basic authentication to true)
- name: create a instance
gcp_compute_instance:
state: present
name: "{{ vm_name }}"
machine_type: "{{ machine_type }}"
metadata:
startup-script: |
New-LocalUser -AccountNeverExpires:$true -Password ( ConvertTo-SecureString -AsPlainText -Force 'Password123!') -Name 'adminuser1' |Add-LocalGroupMember -Group administrators
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
disks:
- auto_delete: true
boot: true
source: "{{ disk }}"
- auto_delete: true
boot: false
interface: NVME
type: SCRATCH
initialize_params:
disk_type: local-ssd
- auto_delete: true
boot: false
interface: NVME
type: SCRATCH
initialize_params:
disk_type: local-ssd
network_interfaces:
- network: "{{ network }}"
zone: "{{ zone }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
register: instance
CodePudding user response:
The fine manual says the key should be, in your case, windows-startup-script-ps1:
since that script is powershell