0

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
Zeitounator
  • 38,476
  • 7
  • 53
  • 66
pugazhendhi_r
  • 101
  • 2
  • 8
  • While this is blatantly off-topic for a programming stack exchange, [the fine manual](https://cloud.google.com/compute/docs/instances/startup-scripts/windows#metadata-keys) says the key should be, in your case, `windows-startup-script-ps1:` – mdaniel May 10 '22 at 14:41
  • Thanks, after changing the parameter to windows-startup-script-ps1, it worked. This can be marked as closed. – pugazhendhi_r May 11 '22 at 06:05
  • It's your question, so you control its lifecycle. You can delete it, or accept the answer if this is the kind of mistake someone else would make in the future. It depends on how you came to the conclusion you just needed to use `startup-script`; if you just made that up, then delete this question. If you found that out in some blog post, accept the answer to warn others – mdaniel May 11 '22 at 14:37

1 Answers1

2

The fine manual says the key should be, in your case, windows-startup-script-ps1: since that script is powershell

mdaniel
  • 31,240
  • 5
  • 55
  • 58